I am trying to read a CSV file with Python with the following code:
with open("example.txt") as f:
c = csv.reader(f)
for row in c:
print row
My example.txt
has only the following content:
Hello world!
For UTF-8 or ANSI encoded files, this gives me the expected output:
> ["Hello world!"]
But if I save the file as UTF-8 with BOM I get this output:
> ["\xef\xbb\xbfHello world!"]
Since I do not have any control over what files the user will use as input, I would like this to work with BOM as well. How can I fix this problem? Is there anything I need to do to ensure that this works for other encodings as well?