# 保存到文件中
file_name = 'G:/pycode/mahongpengTest/biquge/dawangraoming/' + str(novel_chapter) + '.txt'
with open(file_name_utf8,'a') as f:
f.write(novels)
f.close()
报错信息如下
IOError: [Errno 22] invalid mode ('a') or filename
后来查找问题原因又是因为中文编码的问题
# 保存到文件中
file_name = 'G:/pycode/mahongpengTest/biquge/dawangraoming/' + str(novel_chapter) + '.txt'
# 将中文编码设置为 utf8
file_name_utf8 = unicode(file_name,'utf8')
with open(file_name_utf8,'a') as f:
f.write(novels)
f.close()