[Python-ideas] Compact repr operator (i.e., __short_repr__)

Ben Finney ben+python at benfinney.id.au
Mon Feb 8 23:47:43 EST 2016


Greg Ewing <greg.ewing at canterbury.ac.nz> writes:

> Mahmoud Hashemi wrote:
> > I was curious if what kind of interest there would be in adding an
> > overridable method to types to allow getting back a repr, but a
> > predictably short one.
>
> If you just want to know the type and identity of an object,
> you can use object.__repr__(x).

Or, to avoid calling dunder methods directly, use ‘type(x)’ and ‘id(x)’.

Whether all these suggestions address the stated requirement will depend
on how predictable is meant by “predictably short”.

-- 
 \            “All persons, living and dead, are purely coincidental.” |
  `\                                       —_Timequake_, Kurt Vonnegut |
_o__)                                                                  |
Ben Finney



More information about the Python-ideas mailing list