UnicodeDecodeError时使用cyryllic [英] UnicodeDecodeError while using cyryllic

查看:114
本文介绍了UnicodeDecodeError时使用cyryllic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a module which contains only (it's only example. Problem is in much bigger module):

# -*- 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>

我正在使用抛光窗口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中的一个bug。

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时使用cyryllic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆