csv - Unicode Error on Python -
so i'm trying make table csv table has unicode characters in it:
with open('test1.csv', 'w') csvfile: writer = csv.writer(csvfile) [writer.writerow(r) r in table] i error every time try run program, though:
unicodeencodeerror: 'ascii' codec can't encode characters in position 8-10: ordinal not in range(128) how fix this?
assuming you're using python2:
with open('test1.csv', 'wb') csvfile: writer = csv.writer(csvfile) r in table: writer.writerow([x.encode('utf-8') x in r]) of course, when open csv file, need decode using same encoding:
with open('test1.csv') csvfile: reader = csv.reader(csvfile.decode('utf-8')) (nb: if used python3, none of necessary - original example work fine is).
Comments
Post a Comment