UnicodeEncodeError during repr()

Martin v. Loewis martin at v.loewis.de
Mon Apr 19 02:52:26 EDT 2010


> Do I need to do something especial to get repr to work strictly
> with unicode?

Yes, you need to switch to Python 3 :-)

> Or should __repr__ *always* return bytes rather than unicode?

In Python 2.x: yes.

> What about __str__ ?

Likewise.

> If both of these are supposed to return bytes,
> then what method should I use to define the unicode representation
> for instances of a class?

__unicode__.

HTH,
Martin



More information about the Python-list mailing list