I am trying to wrap my head around this for a while now and have not yet seen any solution that does not confuse me.
I got a script in python that should write an array with words (German Names) into an excel file.
cell = [name_1, name_2, name_3]
import csv
fl = open('company_data.csv', 'w')
writer = csv.writer(fl)
writer.writerow(['Name_1', 'Name_2', 'Name_3'])
for values in cell:
writer.writerow(values)
fl.close()
The error that comes is ...,line 135, in writer.writerow(values) UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 0: ordinal not in range(128) [Finished in 1.2s with exit code 1]
The names include the German characters ü,ä,ö etc.
How do I fix this?
python3explicitly instead ofpythononly? Had the same problem, had a#!/usr/bin/env pythonshebang, with#!/usr/bin/env python3everything worked fine. If you're not on *nix, usepython3 myfile.pyand notpython myfile.py:) - criztovyl