即使我试图用python的gzip.open(),它似乎总是使用cp1252.py对文件内容进行编码。 我的代码:
with gzip.open('file.gz', 'rt', 'cp1250') as f:
content = f.read()
回应:
File "C:\Python34\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 52893: character maps to undefined
Python 3.x版
gzip.open
为defined为:因此,
gzip.open('file.gz', 'rt', 'cp1250')
向它发送以下参数: -文件名='文件.gz' -模式='rt' -压缩机液位='cp1250'这显然是错误的,因为其目的是使用“cp1250”编码。
encoding
参数可以作为第四个位置参数或关键字参数发送:Python 2.x版
{{a2>在读取^数据之后^不接受^文本:
^{pr2}$相关问题 更多 >
编程相关推荐