python打开文件错误

1a1*_*11a 3 python python-2.7

我正在尝试打开一些文件,并且我知道使用UTF-8编码的文件中存在一些错误,所以我在python3中要做的是

open(fileName, 'r', errors = 'ignore') 
Run Code Online (Sandbox Code Playgroud)

但是现在我需要使用python2,这样做的相应方式是什么?

以下是我更改为编解码器后的代码

    with codecs.open('data/journalName1.csv', 'rU', errors="ignore") as file:
        reader = csv.reader(file)
        for line in reader:
            print(line) 
Run Code Online (Sandbox Code Playgroud)

文件在这里https://www.dropbox.com/s/9qj9v5mtd4ah8nm/journalName.csv?dl=0

Was*_*oth 5

Python 2不使用内置的open函数支持此功能。相反,您必须使用编解码器。

import codecs
f = codecs.open(fileName, 'r', errors = 'ignore')
Run Code Online (Sandbox Code Playgroud)

如果您决定将来需要切换python版本,则此功能适用于Python 2和3。