UnicodeEncodeError:' charmap'编解码器不能对0-3位的字符进行编码

时间:2016-09-14 10:20:38

标签: python python-3.x

我有以下两个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'

0 个答案:

没有答案