我在python中尝试将文本文件转换为字典时遇到值错误
我正在从api获取该文件
filename=open('/sbranch/CTK/SAP/hkeep/vrp.json','r')
dictionary = {}
with open("/sbranch/CTK/SAP/hkeep/vrp.json", "r") as file:
for line in file
key, value = line.strip()
dictionary[key] = value
print(dictionary)
以下是错误消息:
key, value = line.strip()
ValueError:需要超过1个值才能解包
这是一个打开json文件并将其加载到python字典的简单函数:
如果您是从api获取文件,实际上可以使用请求库直接获取:
安装:
这将从json响应中为您提供一个字典(如果有json):
相关问题 更多 >
编程相关推荐