[Python-ideas] __repr__: to support pprint
boekewurm at gmail.com
Tue Feb 28 20:58:35 EST 2017
On 1 March 2017 at 02:18, qhlonline <qhlonline at 163.com> wrote:
> Yes, We are both python users with languages OTHER then English, It is a
> headache when looking at the print output of dicts with other language
> encoding. They are just byte array. I am using python2.7
Please note that unless this is still a problem in python 3, this is
unlikely to be changed.
__repr__ is (as per the docs) 'a printable string representation of
the object'. If this were to get changed, many APIs might be broken
due to tuples not having the same methods and/or features as strings,
e.g. you cannot use them as a path. Not saying that they will, but
it's potentially breaking a lot of code which interacts with other
programs, and maybe even some internals.
You are free to experiment with overriding/extending __repr__ for your
internal usage, but please note that it might break external libraries
depending on obj.__repr__ or repr(obj), and print() might break when
using built-in types as containers for your objects.
I am a -1 on changing __repr__'s signature.
More information about the Python-ideas