Thanks Karen.

This is a script that fetched some json from a remote service. I  
switched from using the normal simplejson module to the one provided  
by Django and that seems to decode things in a unicode safe way.

On May 21, 2009, at 8:48 AM, Karen Tracey <kmtra...@gmail.com> wrote:

> I see I specified the unicode string incorrectly in my shell  
> example.  Turns out it doesn't make a difference in this case except  
> for the specifics of the exception, but what it should have been was:
>
> >>> u = u'\u2013'
> >>> stderr = open('/tmp/stderr.ascii.out', 'w')
> >>> print >> stderr, '%s' % u
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013'  
> in position 0: ordinal not in range(128)
> >>> import codecs
> >>> stderr = codecs.open('/tmp/stderr.utf8.out', mode='w',  
> encoding='utf-8')
> >>> print >> stderr, '%s' % u
> >>> quit()
>
> Karen
>
> >

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to