UnicodeDecodeError while using cyryllic(使用西里尔字母时出现 UnicodeDecodeError)
问题描述
我有一个只包含的模块(它只是一个例子.问题出在更大的模块中):
I have a module which contains only (it's only example. Problem is in much bigger module):
# -*- coding: utf-8 -*-
"януари"
执行时我得到:
File "C:Program FilesJetBrainsPyCharm 107.130helperspydevpydevd.py", line 1184, in <module>
debugger.run(setup['file'], None, None)
File "C:Program FilesJetBrainsPyCharm 107.130helperspydevpydevd.py", line 947, in run
line = stream.readline() #Should not raise an exception even if there are no more contents
File "C:Python32libencodingscp1250.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x83 in position 31: character maps to <undefined>
我正在使用波兰语 windows xp 和 python 3.2 .我必须更改才能正确执行此模块
I'm using polish windows xp and python 3.2 . What I must to change to properly execute this module
推荐答案
不是那个模块的问题,好像是PyCharm的问题.它显然会读取您的文件,并假定它是 cp1250,即使它被指定为 utf-8.所以这是 PyCharm 中的一个错误.
That module is not the problem, it seems to be a problem with PyCharm. It apparently reads your file, and assumes it's cp1250, even when it's specified to be utf-8. So that's a bug in PyCharm.
它应该以二进制形式打开文件,读取第一行以查看它是否具有编码,否则它应该假定它是 UTF-8.(虽然在 Python 2 下确实应该假设它是 ASCII,但 UTF-8 已经足够好了).
It should open the file as binary, read the first line to see if it has an encoding, in other case it should assume it to be UTF-8. (Although it should really assume it to be ASCII under Python 2, but UTF-8 is good enough).
这篇关于使用西里尔字母时出现 UnicodeDecodeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!