本节内容:
按特定字符集读写文件
例子:
>>> import codecs;
>>> out.close();
>>> out=codecs.open('test2.txt','w','utf-8');
>>> out.write("This is 测试写入中文,使用UTF-8字符集.");
>>> out.close();
>>> import codecs;
>>> out=codecs.open('test2.txt','r','utf-8');
>>> for line in out:
print(line);
This is 测试写入中文,使用UTF-8字符集.
>>> out.close();
>>>查看更多python 教程