[issue5876] __repr__ returning unicode doesn't work when called implicitly

Tomasz Melcer report at bugs.python.org
Mon Sep 5 19:27:42 CEST 2011


Tomasz Melcer <liori at o2.pl> added the comment:

Debian SID. No, it wasn't.

Python 2.7.2+ (default, Aug 16 2011, 09:23:59) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class T(object):
...     def __repr__(self): return u'あみご'
... 
>>> T().__repr__()
u'\u3042\u307f\u3054'
>>> print T().__repr__()
あみご
>>> T()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
>>> print T()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
>>> import sys
>>> sys.stdin.encoding
'UTF-8'
>>> sys.stdout.encoding
'UTF-8'

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5876>
_______________________________________


More information about the Python-bugs-list mailing list