python __repr__

Ref: http://stackoverflow.com/questions/1984162/purpose-of-pythons-repr

__repr__ should return a printable representation of the object, 


A simple example:

>>> class Point:
...   def __init__(self, x, y):
...     self.x, self.y = x, y
...   def __repr__(self):
...     return 'Point(x=%s, y=%s)' % (self.x, self.y)
>>> p = Point(1, 2)
>>> p
Point(x=1, y=2)

Last updated

Was this helpful?