__str__ vs. __repr__

Gerrit Holl gerrit.holl at pobox.com
Mon Nov 1 20:21:18 CET 1999


Randall Hopper wrote:
> 
> 1) Is there a convention for what __str__ and __repr__ should return for
>    classes?

__str__ should return a string, __repr__ may also return, for example, a
dictionairy.

> 2) Or, whatever they return, should they return the same value?

I don't know: I think it's wrong to use both.

regards,
Gerrit.
-- 
linuxgames.nl.linux.org	 All about games on Linux in Dutch (under construction).
www.nl.linux.org	       The Dutch resource for Dutch Linux documentation.
www.nl.linux.org/discoverb		    Learn foreign words and definitions.
www.nl.linux.org/~gerrit/asperger	 I'm an Asperger, go here for more info.
www.nl.linux.org/~gerrit			    About me and pictures of me.




More information about the Python-list mailing list