我使用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