我试图在Python 3.6.0中将符号฿添加到文本文件中,但我一直收到错误:
UnicodeEncodeError: 'charmap' codec can't encode character '\u0e3f'
in position 0: character maps to <undefined>
我也尝试将f.write('฿')
更改为f.write('฿'.encode("\u0e3f"))
但我收到错误:
LookupError: unknown encoding: ฿
我尝试了几种不同的方法,但我仍然遇到错误。是否有一些我可能遗失的东西?任何提示/答案将不胜感激!
答案 0 :(得分:1)
您只需设置输出文件编码:
outstring = "฿"
with open("f:/toolbuild/temp/temp.txt", "wt", encoding="utf-8") as outfile:
outfile.write(outstring)
效果很好!