用于输出垂直矩形的Python脚本
我正试图开发一个脚本来检测记事本文件中那些奇怪的垂直矩形。我指的是您在下图中看到的内容:用于输出垂直矩形的Python脚本,python,utf-8,fonts,Python,Utf 8,Fonts,我正试图开发一个脚本来检测记事本文件中那些奇怪的垂直矩形。我指的是您在下图中看到的内容: ![垂直矩形][1] 我确实尝试了.encode(“utf-8”)函数以及utf-18和utf-32以使字体可读,但每次尝试都收到以下错误消息: Traceback (most recent call last): File "<interactive input>", line 1, in <module> UnicodeDecodeError: 'ascii' codec c
![垂直矩形][1]
我确实尝试了.encode(“utf-8”)函数以及utf-18和utf-32以使字体可读,但每次尝试都收到以下错误消息:
Traceback (most recent call last): File "<interactive input>", line
1, in <module> UnicodeDecodeError: 'ascii' codec can't decode byte
0xef in position 10: ordinal not in range(128)
任何帮助都将不胜感激 您可以这样做:
>>> import codecs
>>> codecs.decode(b"\xfe\xfe\xff\xff", "utf-8", "replace")
'����'
将此与:
>>> codecs.decode(b"\xfe\xfe\xff\xff", "utf-8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 0: invalid start byte
编解码器。解码(b“\xfe\xfe\xff\xff”,“utf-8”)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/usr/lib/python3.4/encodings/utf_8.py”,第16行,解码
返回编解码器.utf_8_解码(输入,错误,真)
UnicodeDecodeError:“utf-8”编解码器无法解码位置0中的字节0xfe:无效的开始字节
您可以通过注册自定义编解码器来获得对数据解码的更多控制,有关自定义编解码器,请参阅
如果要猜测字符串编码以正确输出,请使用。它仍然没有那么好,所以最后的办法是使用暴力,然后依次尝试每个可用的编解码器(有关它们的列表,请参见上面的链接)。您混淆了unicode、编码、字符和字体。我建议你读一读。另外:获取那些“奇怪的矩形”并在你的文件中搜索它们将毫无用处。这些矩形不在文本中,它们是软件表示无法解码文本的一种方式。在其第一种形式中,这是一种误导。如果OP复制并粘贴那些“奇怪的矩形”,并试图通过搜索来识别编码模糊的文件,那么他将一事无成。
>>> codecs.decode(b"\xfe\xfe\xff\xff", "utf-8")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 0: invalid start byte