【发布时间】:2015-09-05 12:23:31
【问题描述】:
我正在使用 Python 3.4 将 unicode 字符串写入文件。 文件写好后,打开一看,完全是不同的字符集。
代码:-
# -*- coding: utf-8 -*-
with open('test.txt', 'w', encoding='utf-8') as f:
name = 'أبيض'
name.encode("utf-8")
f.write(name)
f.close()
f = open('test.txt','r')
for line in f.readlines():
print(line)
输出:-
أبيض
提前致谢
【问题讨论】:
标签: python python-3.x unicode utf-8 mojibake