【发布时间】:2022-11-30 15:25:14
【问题描述】:
【问题讨论】:
-
请直接粘贴您的代码而不是放入图像。
-
with open(r'path/to/read/','r') as file: data = json.load(file)在那里面加'r'..
标签: python json visual-studio-code
【问题讨论】:
with open(r'path/to/read/','r') as file: data = json.load(file)在那里面加'r'..
标签: python json visual-studio-code
您必须为 open() 函数指定一种模式。在这种情况下,我认为您正在尝试读取文件,因此您的模式将是“r”。你的代码应该是:
with open(r'path/to/read/','r') as file:
data = json.load(file)
您的代码现在应该可以运行了。
【讨论】:
导入系统
导入操作系统
导入 json
def JsonRead(str):
f = open(str,encoding='utf-8')
data = json.load(f)
return data
然后在项目中导入JsonRead
【讨论】: