__str__ vs. __repr__

piet at cs.uu.nl piet at cs.uu.nl
Wed Nov 10 10:41:35 CET 1999


>>>>> Toby Dickenson <htrd90 at zepler.org> (TD) writes:

TD> "Tim Peters" <tim_one at email.msn.com> wrote:
>> Let me back off to what repr and str "should do":
>> 
>> repr(obj) should return a string such that
>> eval(repr(obj)) == obj

TD> I don't understand the motivation for this requirement. Why would
TD> anyone want to pass such a string to eval? If you anticipate the need
TD> for reconstructing the object from a textual representation, then
TD> surely pickle is a better option?

for example, if you would want to write a couple of variables to a file in
the form of python statements: var=value.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: Piet.van.Oostrum at gironet.nl




More information about the Python-list mailing list