从fi获取字典列表作为输入

2024-04-26 14:34:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从一个名为IP.txt文件然后将其存储在一个名为lst的变量中:

[{"date":"30-Apr-12","price":583.98},{"date":"1-May-12","price":58}]

我该怎么做?你知道吗


Tags: 文件iptxtdatepriceaprmaylst
1条回答
网友
1楼 · 发布于 2024-04-26 14:34:44
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'}]

相关问题 更多 >