difference between __repr__() and __str__()

Emile van Sebille emile at fenx.com
Mon Feb 28 20:31:37 EST 2000


I like that eval(repr(obj)) stay true.  On that basis, the repr(obj)
should create a string such that obj == eval(repr(obj)).

Emile van Sebille
emile at fenx.com
-------------------


----- Original Message -----
From: Gregoire Welraeds <greg at perceval.be>
To: <python-list at python.org>
Sent: Monday, February 28, 2000 9:33 AM
Subject: difference between __repr__() and __str__()


> The question is in the subject. According to the Python reference
manual,
> page 17
>
> __repr__: called to compute the official string representation of an
> object. This should like a valid Python expression that can be used to
> recreate an object with the same value.
>
> __str__: differs from repr in that in does not have to be a valid
python
> expression: a more conveniant or concise representation maybe used
> instead.
>
> What is a valid Python expression ?
> I though that repr was called by repr and by string conversion (as
> mentionned early in the doc)not to recreate an object ?
> What is the use of an official string representation against the
> non-official ?
>
> --
> Life is not fair
> But the root password helps
> --
>
> Gregoire Welraeds
> greg at perceval.be
> Perceval Development team
> ----------------------------------------------------------------------
---------
> Perceval Technologies sa/nv Tel: +32-2-6409194
> Rue Tenbosch, 9 Fax: +32-2-6403154
> B-1000 Brussels general information:   info at perceval.net
> BELGIUM technical information: helpdesk at perceval.net
> URL: http://www.perceval.be/
> ----------------------------------------------------------------------
---------
>
>
>
> --
> http://www.python.org/mailman/listinfo/python-list
>






More information about the Python-list mailing list