utf\ U 7解码错误

2024-10-06 13:07:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用以下python代码来解码“文本”文件:

import codecs, os, sys
fd = open("c:/a.txt", 'rb')
rb = fd.read()
s = codecs.decode(rb, 'utf_7')
print(s)

运行时出现以下错误:

UnicodeDecodeError: 'utf7' codec can't decode byte 0xc3 in position 3: unexpected special character

但是“文本”文件可以由iconv实用程序解码,如下所示:

$iconv -f UTF-8 -t UTF-7 a.txt
01 +ANYA2AC5AOkAywDVAMEAqw

怎么了?你知道吗


Tags: 文件代码文本importtxtossysopen