Message143559
> Debian SID. No, it wasn't.
Oh ok, gotcha: repr() always returns a str string. If obj.__repr__() returns a
Unicode string, the string is encoded to the default encoding. By default, the
default encoding is ASCII.
$ ./python -S
Python 2.7.2+ (2.7:85a12278de69, Sep 2 2011, 00:21:57)
[GCC 4.6.0 20110603 (Red Hat 4.6.0-10)] on linux2
>>> import sys
>>> sys.setdefaultencoding('ISO-8859-1')
>>> class A(object):
... def __repr__(self): return u'\xe9'
...
>>> repr(A())
'\xe9'
Don't do that at home! Change the default encoding is not a good idea.
I don't think that repr(obj) can be changed to return Unicode if
obj.__repr__() returns Unicode. It is too late to change such thing in Python
2. |
|
Date |
User |
Action |
Args |
2011-09-05 20:07:15 | vstinner | set | recipients:
+ vstinner, lemburg, ezio.melotti, eric.araujo, r.david.murray, liori, Nam.Nguyen |
2011-09-05 20:07:15 | vstinner | link | issue5876 messages |
2011-09-05 20:07:14 | vstinner | create | |
|