我无法正确导入此 json 文件


if __name__ == '__main__':
import json
data = json.load(open('C:\Users\lenovo\Documents\FinPy\FinPy\Data\letras.json)')
print (data)

编辑: 错误消息如下:

runfile('C:/Users/lenovo/Documents/FinPy/FinPy/test.py', wdir='C:/Users/lenovo/Documents/FinPy/FinPy')
Traceback (most recent call last):
File "C:UserslenovoAnaconda3libsite-packagesIPythoncoreinteractiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-699848768d77>", line 1, in <module>
runfile('C:/Users/lenovo/Documents/FinPy/FinPy/test.py', wdir='C:/Users/lenovo/Documents/FinPy/FinPy')
File "C:UserslenovoAnaconda3libsite-packagesspyderutilssitesitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:UserslenovoAnaconda3libsite-packagesspyderutilssitesitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/lenovo/Documents/FinPy/FinPy/test.py", line 40
#dict_tir = {n: tir(i) for n, i in data['mercado'].items()}
^
SyntaxError: unexpected EOF while parsing

letras.json有这个:

{
"mercado" : {
"LELIQ" : { "precio" :  98.63, "capital" : 100.0000, "plazo" :   7 },
"I21N8" : { "precio" :  94.40, "capital" : 100.0000, "plazo" :  42 },
"LTPN8" : { "precio" : 103.00, "capital" : 110.6814, "plazo" :  51 },
"I19D8" : { "precio" :  90.25, "capital" : 100.0000, "plazo" :  70 },
"LTPD8" : { "precio" : 102.75, "capital" : 114.5642, "plazo" :  79 },
"LTPE9" : { "precio" : 101.90, "capital" : 118.5253, "plazo" : 113 },
"LTPF9" : { "precio" : 101.15, "capital" : 122.7838, "plazo" : 141 },
"LTPM9" : { "precio" :  98.00, "capital" : 123.1152, "plazo" : 170 },
"LTPS9" : { "precio" : 102.77, "capital" : 151.7697, "plazo" : 355 }
},
"portfolio" : {
"LTPN8" : 0.3,
"LTPD8" : 0.2,
"LTPE9" : 0.2,
"LTPF9" : 0.1,
"LTPM9" : 0.1,
"LTPS9" : 0.1
}
}

试试这个。

import json
F = open("C:RUTEYOURFILE","r") 
print F, "this is your file"
saved = F.read()
data = json.loads(saved)
print (data["mercado"])

蟒蛇 v2.7.13 (我不太懂英语,所以这就是为什么我的评论很短(

相关内容

  • 没有找到相关文章

最新更新