如何在读取大文件时修复此错误?python

如何在读取大文件时修复此错误?python,python,Python,该文件是IMDB数据库中的女演员部分。 尝试读取特定行时收到的错误是: File "C:\Program Files\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 2, in <module> if __name__ == '__main__': File "C:\Python33\Lib\codecs.py", line 300, in decode (result, consumed) = se

该文件是IMDB数据库中的女演员部分。 尝试读取特定行时收到的错误是:

  File "C:\Program Files\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 2, in <module>
    if __name__ == '__main__':
  File "C:\Python33\Lib\codecs.py", line 300, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
builtins.UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 3976: invalid continuation byte

如果它来自IMDB网站,它似乎使用iso-8859-1(
),请在打开文件时尝试使用此编解码器。

您的文件可能不包含UTF8?尽管您的回溯不适合您的代码。完全这就好像WingIDE被什么东西绊倒了,而不是你的代码。还有,为什么你要把所有的行都读入
lenlines
,然后用长度替换这些行?我也不会将
linecache
用于此任务;该模块的目标是加载python模块,而不是加载普通文件。例如,它标记文件以查找Python编解码器提示。
with open("actresses.list",encoding = 'utf-8') as i:
     lenlines=i.readlines()
lenlines = (len(lines)) 
import linecache
print(lenlines)
print(linecache.getline("actresses.list",5))