3

我有一个只包含的模块(它只是一个例子。问题出在更大的模块中):

# -*- coding: utf-8 -*-
"януари"

执行时我得到:

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\pydev\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>

我正在使用波兰语 windows xp 和 python 3.2 。我必须更改才能正确执行此模块

4

2 回答 2

5

那个模块不是问题,它似乎是 PyCharm 的问题。它显然会读取您的文件,并假定它是 cp1250,即使它被指定为 utf-8。所以这是 PyCharm 中的一个错误。

它应该以二进制形式打开文件,读取第一行以查看它是否具有编码,否则它应该假定它是 UTF-8。(虽然它应该真的假设它在 Python 2 下是 ASCII,但 UTF-8 已经足够好了)。

于 2011-05-24T11:07:46.930 回答
0

CTRL在 PyCharm 中,您可以在 Settings ( ++ ALT) S|中指定 UTF-8 编码。文件编码。那应该行得通。

于 2011-05-24T15:04:45.000 回答