Python 3 How to ignore errors when writing UTF-8 to file

Viewed 3509

I have the following program:

with open(r'C:\s_f.csv', 'w', encoding="utf-8", errors="ignore") as outf:
    with open(r'C:\street.csv', 'r', encoding="utf-8", errors="ignore") as f:
        for line in f:
            out_line = line
            out_line = out_line.replace('"','¬')
            out_line = out_line.replace(',','~')
            outf.write(out_line)

For some reason I am still getting:

File "c:\Program Files\Anaconda3\streets.py", line 5
    SyntaxError: Non-UTF-8 code starting with '\xac' in file c:\Program Files\Anaconda3\streets.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 

How can I ignore the UTF-8 errors in Python 3?

2 Answers
Related