import codecs f = codecs.open('test.txt', 'w', 'utf-8') f.write('中文') f.close() 运行结果: 相关文章: xmlWriter 以UTF-8格式写xml问题 2021-12-25 python 写文件,utf-8问题 2022-12-23 (转)Delphi读写UTF-8、Unicode格式文本文件 2022-12-23 python3 以utf-8编码写文件 2022-12-23 python 读取带BOM的utf-8格式文件 2022-12-23 Python:将utf-8格式的文件转换成gbk格式的文件 2021-07-24 ascii文件转为utf-8格式 2022-12-23