[Python-ideas] __repr__: to support pprint
mlet_it_bew at 126.com
Tue Feb 28 21:27:21 EST 2017
It has not to break current code:
def repr(obj, allowed_tuple = False):
r = type(obj).__repr__()
if isinstance(r, tuple):
r = make_str(type(obj), r)
At 2017-03-01 09:58:35, "Matthias welp" <boekewurm at gmail.com> wrote:
>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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas