您现在的位置是:课程教程文章

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

2023-12-18 18:03课程教程文章 人已围观

问题描述:

获取了接口返回的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]+',')
课程教程:python2.7无法写入txt解决方法

上一篇:怎样打开数据库mongodb

下一篇:没有了

站点信息

  • 文章统计篇文章