【发布时间】:2023-03-18 23:21:01
【问题描述】:
class A:
def read_json(self,file_json_path):
try:
with open(file_json_path) as fd:
content = json.dumps(fd)
except IOError:
print 'exception while opening a file %s\n'%(file_json_path)
我是 python 新手,谁能指导我,如何模拟打开文件和读取 json 数据。
【问题讨论】:
-
我会使用一个已知的小型 json 文件,并且您会知道相对路径,因为 testdata 文件夹可能是测试所在的子文件夹。
-
您应该使用临时文件。关闭后它会立即删除它。