我使用python脚本创建两个文件,第一个文件是JSON,第二个是HTML文件,我的下面是创建json文件,但创建HTML文件时出现错误。有人可以帮我解决这个问题吗?我是新来的Python脚本,因此将非常感激,如果你能提出一些解决方案在python中创建多个文件时获取错误
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import json
JsonResponse = '[{"status": "active", "due_date": null, "group": "later", "task_id": 73286}]'
def create(JsonResponse):
print JsonResponse
print 'creating new file'
try:
jsonFile = 'testFile.json'
file = open(jsonFile, 'w')
file.write(JsonResponse)
file.close()
with open('testFile.json') as json_data:
infoFromJson = json.load(json_data)
print infoFromJson
htmlReportFile = 'Report.html'
htmlfile = open(htmlReportFile, 'w')
htmlfile.write(infoFromJson)
htmlfile.close()
except:
print 'error occured'
sys.exit(0)
create(JsonResponse)
我用下面的在线Python编辑器来执行我的代码:
在某些地方使用'open'而不是别人是......不可思议的。 – tripleee