django - Getting error in python with characters from word document -
i have text entered in text box
‘f’fdsfs’`124539763~!@#$%^’’;’””::’
i coverting json , comes as
"\\u2018f\\u2019fdsfs\\u2019`124539763~!@#$%^\\u2019\\u2019;\\u2019\\u201d\\u201d::\\u2019e"
now when writing csv file error
'ascii' codec can't encode character u'\u2018' in position 0: ordinal not in range(128)
csv.writer(data)
i tried data.encode('utf-8')
data.decode('unicode-escape')
didn't work
csv module not support unicode use https://github.com/jdunck/python-unicodecsv instead
although im not sure \u2018 part of utf-8 charset
x = "\\u2018f\\u2019fdsfs..."; j = json.loads('"' + x + '"'); print j.encode('cp1252') ‘f’fdsfs...
note being encoded cp1252
>>> import unicodecsv csv #https://github.com/jdunck/python-unicodecsv >>> x = "\\u2018f\\u2019fdsfs..."; j = json.loads('"' + x + '"'); >>> open("some_file.csv","wb") f: ... w = csv.writer(f,encoding="cp1252") ... w.writerow([j,"normal"]) ... >>>
here csv file : https://www.dropbox.com/s/m4gta1o9vg8tfap/some_file.csv
Comments
Post a Comment