How to print non-ASCII characters in Python

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2009-11-10T10:48:50Z Indexed on 2010/04/10 12:53 UTC
Read the original article Hit count: 360

Filed under:
|

I have a problem when I'm printing (or writing to a file) the non-ASCII characters in Python. I've resolved it by overriding the str method in my own objects, and making "x.encode('utf-8')" inside it, where x is a property inside the object.

But, if I receive a third-party object, and I make "str(object)", and this object has a non-ASCII character inside, it will fail.

So the question is: is there any way to tell the str method that the object has an UTF-8 codification, generically? I'm working with Python 2.5.4.

© Stack Overflow or respective owner

Related posts about python

Related posts about extended-ascii