import codecs
f = codecs.open('test.txt', 'w', 'utf-8')
f.write('中文')
f.close()

运行结果:

python3导入utf-8 python写入文件utf8_python3导入utf-8