How to change default behaviour of a class?
mwh21 at cam.ac.uk
Mon Aug 30 12:37:36 CEST 1999
"Gerhard W. Gruber" <g.gruber at xsoft.co.at> writes:
> How can I change what is printed when I use the statement "print class"?
> Usually this leads to an output like <class instance at 9aad60> but I
> rather want it to print variables contained in my class instead of the
> pointer adress.
Add a __repr__ method:
self.a = 1
return "self.a = %s"%self.a
C() => "self.a = 1" appears on stdout.
More information about the Python-list