您好,欢迎来到华拓网。
搜索
您的当前位置:首页python2.7无法写入txt解决方法

python2.7无法写入txt解决方法

来源:华拓网

问题描述:

获取了接口返回的json数据,然后按行读取所有数据,把想着数据写到txt时,中文总显示例如: u'\u4e5d\u52a9\u5e55\

解决方法:

导入如下:

import sys
reload (sys)
sys.setdefaultencoding('utf-8')

写文件时直接open后用write即可:

file = open(str(f) + '.txt', 'w')     #打开文本文件,如果没有将新建
file.write('orig_id:%s'%orig_id[b]+',')

Copyright © 2019- huatuo3.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务