Removing BOM from gzip'ed CSV in Python
I'm using the following code to unzip and save a CSV file: with gzip.open(filename_gz) as f: file = open(filename, "w"); output = csv.writer(file, delimiter = ',') output.writerows(csv.reader(f, dialect='excel', delimiter = ';')) Everything seems to work, except for the fact that the first characters in the file are unexpected. Googling around seems to indicate that it is due to BOM in the file. I've read that encoding the content in utf-8-sig should fix the issue. However, adding: .read().encoding('utf-8-sig') to f in csv.reader fails with: File "ckan_gz_datastore.py", line 16, in <module>