Python 文件写入中文问题

来源:互联网 发布:iope水乳 知乎 编辑:程序博客网 时间:2024/06/06 00:47

文件声明为

# coding=utf-8开头重载编码import sysreload(sys) sys.setdefaultencoding('utf-8')以二进制写入文件file=open('tmp.txt','wb')写入字符串前转换编码为utf-8file.write(str.encode('utf-8'))希望能给其他人以借鉴。
0 0