export a list as a csv file in python and getting UnicodeEncodeError -
i want csv file list. list:
temp = ['سلام' , 'چطوری' ]
members of list in persian language. tried csv file code:
import csv open("output.csv", "wb") f: writer = csv.writer(f) writer.writerows(temp)
but terminal gives me error: unicodeencodeerror: 'ascii' codec can't encode character u'\u06a9' in position 0: ordinal not in range(128)
how can solve , csv file?
p.s when print temp , see these strings:
[u'\u06a9\u0627\u062e \u0645\u0648\u0632\u0647 \u06af\u0644\u0633\u062a\u0627\u0646 | golestan palace', u'\u062a\u0647\u0631\u0627\u0646', u'\u062a\u0647\u0631\u0627\]
but when call temp[1] this:
کاخ موزه گلستان | golestan palace
how can solve , csv file?
why python encodes data , sometime doesn't?
the csv
library in python 2 cannot handle unicode data. fixed in python 3, not backported. however, there drop-in replacement 3rd party library fixes problem.
try using unicodecsv instead.
Comments
Post a Comment