我有以下两个python文件,当我在python shell中运行它工作正常并打印解码文本但是当我在pythonw.exe中运行时它有这个错误:
错误:
Traceback (most recent call last):
File "C:\main.py", line 2, in <module>
print(lan.encodedtext.decode('utf-8'))
File "C:\Python35\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-3: character maps to <undefined>
main.py:
from x.LV import lan
print(lan.encodedtext.decode('utf-8'))
x \ LV.py:
class Lan():
def __init__(self):
self.encodedtext = b'\xd8\xb3\xd9\x84\xd8\xa7\xd9\x85'
lan = Lan()
它也适用于python shell,它适用于self.encodedtext = b'hello'
。