我在通过文本文件将最后一个数据提取到我的程序中遇到了困难。我对Python非常陌生,如果答案非常简单,请原谅我。从python文本文件中提取数据3
我有这个序列的数据集在一个文本文件中,我已经提取美元作为我的卖出货币英镑作为我的买入货币和0.50443作为我的汇率。但我不知道如何提取成本作为我的交易成本和0.0001作为该变量的相关值。
{"USD_GBP_COST": "0.50443,0.0001", "USD_USD_COST": "1.00000,0.0000", "USD_EUR_COST": "0.73951,0.01211"}
以下是我对其他部分代码:
currency_rates = json.loads(page)
splited_rates = re.compile("([A-Z]{3})_([A-Z]{3})")#split the string which is read from the url,it should be any 3 uppercase characters sperated by a _
for key in currency_rates:
matches=splited_rates.match(key)
log_con_rate = -math.log(float(currency_rates[key]))
selling_currency = matches.group(1).encode('ascii','ignore')
buying_currency = matches.group(2).encode('ascii','ignore')
如果当您运行此会发生什么?什么不在这里工作?你想要什么输出? –
嘿,它给了我这个错误文件“C:\ Python34 \ lib \ json \ decoder.py”,行343,在解码中 obj,end = self.raw_decode(s,idx = _w(s,0).end ()) Value_Error:期望':'分隔符:第1行(第1行)文件“C:\ Python34 \ lib \ json \ decoder.py”,第359行,raw_decode obj,end = self.scan_once(s,idx) 407(char 406) – Hash