试图为python 3.6.0的文件写入符号,但I';我犯了错误
我试图将符号฿添加到Python 3.6.0中的文本文件中,但不断出现错误:试图为python 3.6.0的文件写入符号,但I';我犯了错误,python,python-3.x,python-3.6,Python,Python 3.x,Python 3.6,我试图将符号฿添加到Python 3.6.0中的文本文件中,但不断出现错误: UnicodeEncodeError: 'charmap' codec can't encode character '\u0e3f' in position 0: character maps to <undefined> LookupError: unknown encoding: ฿ 我尝试了几种不同的方法,但仍然会出错。也许有什么东西我遗漏了?如有任何提示/答案,将不胜感激 您只需设置输
UnicodeEncodeError: 'charmap' codec can't encode character '\u0e3f'
in position 0: character maps to <undefined>
LookupError: unknown encoding: ฿
我尝试了几种不同的方法,但仍然会出错。也许有什么东西我遗漏了?如有任何提示/答案,将不胜感激 您只需设置输出文件编码:
outstring = "฿"
with open("f:/toolbuild/temp/temp.txt", "wt", encoding="utf-8") as outfile:
outfile.write(outstring)
很好用 请出示你的密码。此外,您使用
编码的方式也没有意义。encode的参数是编码的名称,类似于f.write('฿'.encode(“utf-8”)
。