newbie: question about "__repr__"
gk_2345 at yahoo.com
Thu Nov 6 05:05:53 CET 2003
"chenyu" <chenyu468 at hotmail.com> wrote in message
news:6143ac23.0311051814.4d9908f at posting.google.com...
> 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
might return "foo('astring')".
More information about the Python-list