Odd json encoding erro
Chris Rebert
clp2 at rebertia.com
Tue Dec 15 18:38:19 EST 2009
On Tue, Dec 15, 2009 at 3:04 PM, Wells <thewellsoliver at gmail.com> wrote:
> Sorry- more detail- the actual problem is an exception thrown when
> running str() on the value, like so:
>
>>>> a = u'St. Paul\u2019s School For Boys (MN) HS'
>>>> print str(a)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in
> position 8: ordinal not in range(128)
>
> Is there some way to run str() against a unicode object?
To repeat what I said earlier, you use the .encode() method instead:
print a.encode('utf8')
Might I recommend reading:
http://www.joelonsoftware.com/articles/Unicode.html
Regards,
Chris
--
http://blog.rebertia.com
More information about the Python-list
mailing list