<p>这种错误怎么办?您正在从文件中读取行。你不知道编码。在</p>
<p>“字节0xed”是什么意思?
“3792号位置”是什么意思?在</p>
<p>我会试着自己回答这个问题,然后转贴,但我有点恼火,因为我花了太多时间来解决这个问题。有没有一种删除/忽略并继续的方法来获得过去的未知编码?我只想读一个文本文件!在</p>
<pre><code>Traceback (most recent call last):
File "./test.py", line 8, in <module>
for x in fin:
File "/bns/rma/local/lib/python3.1/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xed in position 3792: ordinal not in range(128)
</code></pre>
<p>我想我找到了一个愚蠢的方法:):</p>
<pre><code>fin = (x.decode('ascii', 'ignore') for x in fin)
for x in fin: print(x)
</code></pre>
<p>其中errors='ignore'可以是'replace'或其他。这至少遵循了我正在寻找的成语“垃圾进,垃圾出”。在</p>