python2.7无法写入txt解决方法
发布时间:2025-12-12 16:49:05

问题描述:
获取界面返回的json数据,然后按行读取所有数据,并在txt中写下思考数据,例如: u'\u4e5du52a9u5e5
解决方法:
导入如下:
importsys
reload(sys)
sys.setdefaultencoding('utf-8')写文件时直接open,然后用write:
file=open(str(f)+'.txt','w')#打开文本文件,如果没有新建
file.write('orig_id:%s'%orig_id[b]+',') 