如何在 Python 中读写 unicode(UTF-8)文件?
pythonserver side programmingprogramming更新于 2023/11/9 11:24:00
io 模块现在被推荐使用,并且与 Python 3 的开放语法兼容:以下代码用于在 Python 中读写 unicode(UTF-8)文件
示例
import io with io.open(filename,'r',encoding='utf8') as f: text = f.read() # process Unicode text with io.open(filename,'w',encoding='utf8') as f: f.write(text)