我正在尝试为服务器的json文件构建解析器,但是我在声明json_dict
时遇到此问题,同样的代码在python 2.7中正常工作,但是现在我有3.7,我不知道如何修改避免使用[Errno 13] Permission denied
import os
import csv
import json
import sys
from importlib import reload
reload(sys)
file_path = 'C:/Users/admin/Desktop'
dirs = os.listdir(file_path)
file_out = 'C:/Users/admin/Desktop/csv/json-to-csv.csv'
f = csv.writer(open(file_out, "w+"))
f.writerow(['file', 'id'])
for file in dirs:
json_dict = json.loads(open(os.path.join(file_path, file)).read())
print(file)
for key in json_dict:
for key1 in key:
idi = key['id']
f.writerow([file[0:14], idi])
权限错误:[Errno 13]权限被拒绝:'C:/ Users / admin / Desktop \\ csv'