python open file error

python, python-2.7

Solution

Python 2 does not support this using the built-in open function. Instead, you have to uses codecs.

import codecs
f = codecs.open(fileName, 'r', errors = 'ignore')

This works in Python 2 and 3 if you decide you need to switch your python version in the future.

Problem

I am trying to open some file and I know there are some errors in the file with UTF-8 encoding, so what I will do in python3 is ``` open(fileName, 'r', errors = 'ignore') ``` but now I need to use python2, what are the corresponding way to do this? Below is my code after changing to codecs ``` with codecs.open('data/journalName1.csv', 'rU', errors="ignore") as file: reader = csv.reader(file) for line in reader: print(line) ``` And file is here https://www.dropbox.com/s/9qj9v5mtd4ah8nm/journalName.csv?dl=0

Original source