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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用西里尔字母时出现 UnicodeDecodeError


- 计算测试数量的Python单元测试 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01