执行output_json_file 功能函数时候,print 打印出
'encoding' is an invalid keyword argument for this function
的错误
错误代码
def output_json_file(jsonData, jsonFile):
try:
with open(jsonFile, 'w', encoding = 'utf-8') as f:
f.write(jsonData.decode('utf8'))
return jsonFile
except Exception as e:
print "error is: ", e
return
正确代码
将
with open
改为with io.open
,并引入import io
import io
def output_json_file(jsonData, jsonFile):
try:
with io.open(jsonFile, 'w', encoding = 'utf-8') as f:
f.write(jsonData.decode('utf8'))
return jsonFile
except Exception as e:
print "error is: ", e
return
网友评论