newbie: question about "__repr__"

George Kinney gk_2345 at
Thu Nov 6 05:05:53 CET 2003

"chenyu" <chenyu468 at> wrote in message
news:6143ac23.0311051814.4d9908f at
> Hi,
> I have read others' code for study, and found one built-in function
> "__repr__". Could anyone give me an simple example for explaining
> "when and how" to use it.

The customary use of __repr__ is for it to return a string that can be
passed to eval()
and re-create the object.  So for a class 'foo' that takes one string in its
__init__, __repr__
might return "foo('astring')".

More information about the Python-list mailing list