UnicodeDecodeError while using cyryllic
I have a module which contains only (it's only example. Problem is in much bigger module):
# -*- coding: utf-8 -*-
"януари"
While execution I get:
File "C:\Program Files\JetBrains\PyCharm 107.130\helpers\pydev\pydevd.py", line 1184, in <module>
debugger.run(setup['file'], None, None)
File "C:\Program Files\JetBrains\PyCharm 107.130\helpers\py开发者_运维问答dev\pydevd.py", line 947, in run
line = stream.readline() #Should not raise an exception even if there are no more contents
File "C:\Python32\lib\encodings\cp1250.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>
I'm using polish windows xp and python 3.2 . What I must to change to properly execute this module
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.
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).
In PyCharm you can specify UTF-8 encoding in Settings (CTRL+ALT+S) | File encodings. That should work.
精彩评论