unittest.py: what is TestResult.__repr__ ?

Michael Chermside mcherm at destiny.com
Fri Mar 15 15:12:58 EST 2002


The names with leading and trailing double underscores (like "__repr__") 
are "special" names. These correspond to methods (or other things) which 
have special meaning to Python.

For instance "__init__" is the special method which is called to 
initialize new instances of a class when they are created.

"__repr__" is the special method which is called to create a string 
which represents the class. Actually, that's a little bit misleading, 
because I'd give the SAME definition for the special method "__str__". 
Python has two different convert-to-cannonical-string-form methods, 
because in certain cases (eg: strings) it's useful. Normally, __str__ 
will be a "normal" convert-to-string method, and __repr__ will convert 
to some form which would, if executed, re-create the object.

For more information see http://python.org/doc/current/ref/specialnames.html

-- Michael Chermside






More information about the Python-list mailing list