Tuesday, May 1, 2012

Re: HELP with unicode!!!!!



On Tuesday, May 1, 2012, dizzydoc wrote:
Hi ,

i have lost a lot of time looking for a solution.

My problem is, while i a reading csv in python using

csv_file  = open(path_file, "rb")
reader = csv.reader(csv_file)

whenever i perform any operation on the string returned in each cell i
get this error

*** UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0'
in position 34: ordinal not in range(128)

It's a long-standing limitation with the python csv module that it does not handle Unicode well. In fact, it's one of the first things mentioned in the docs:


Further down that page, though, is a snippet of code that you should be able to use (search the page for "unicode_csv_reader")

If that doesn't work, come back here with some code that you've tried and hopefully we can find a solution

Ian


i tried decoding the value as

val.decode('utf-8')

...this helped to reduce a few encodings but gets stuck for
the encoding "\xa0"
Please HELP!





--
Regards,
Ian Clelland
<clelland@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment