当前位置: 首页 > 图灵资讯 > 行业资讯> python2.7无法写入txt解决方法

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]+',')

相关文章

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

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

2025-12-12
python安装lxml模块时发生错误解决方法

python安装lxml模块时发生错误解决方法

2025-12-12
python必选参数是什么意思

python必选参数是什么意思

2025-12-12
python编程什么教材好

python编程什么教材好

2025-12-12
python存储jpg图片出错解决方法

python存储jpg图片出错解决方法

2025-12-11
python代码检测工具及区别

python代码检测工具及区别

2025-12-11