Python 从文件中获取字典列表作为输入
我想从名为IP.txt的文件中获取以下词典列表作为输入,并将其存储在名为lst的变量中:Python 从文件中获取字典列表作为输入,python,list,file,dictionary,Python,List,File,Dictionary,我想从名为IP.txt的文件中获取以下词典列表作为输入,并将其存储在名为lst的变量中: [{"date":"30-Apr-12","price":583.98},{"date":"1-May-12","price":58}] 我应该怎么做?看看这个模块。如果您使用json模块,这是很简单的。 import json with open("IP.txt") as json_file: Ist= json.load(json_file) print(Ist
[{"date":"30-Apr-12","price":583.98},{"date":"1-May-12","price":58}]
我应该怎么做?看看这个模块。如果您使用
json
模块,这是很简单的。
import json
with open("IP.txt") as json_file:
Ist= json.load(json_file)
print(Ist)
>>>[{'price': 583.98, 'date': '30-Apr-12'}, {'price': 58, 'date': '1-May-12'}]