Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
试图为python 3.6.0的文件写入符号,但I';我犯了错误_Python_Python 3.x_Python 3.6 - Fatal编程技术网

试图为python 3.6.0的文件写入符号,但I';我犯了错误

试图为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: ฿ 我尝试了几种不同的方法,但仍然会出错。也许有什么东西我遗漏了?如有任何提示/答案,将不胜感激 您只需设置输

我试图将符号฿添加到Python 3.6.0中的文本文件中,但不断出现错误:

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”)