eval(repr(object)) hardly ever works

Fredrik Lundh fredrik at pythonware.com
Wed Sep 13 11:23:23 EDT 2006


Matthew Wilson wrote:

> I understand that idea of an object's __repr__ method is to return a
> string representation that can then be eval()'d back to life, but it
> seems to me that it doesn't always work. 

when in doubt, read the language reference:

     "If at all possible, this should look like a valid Python
     expression that could be used to recreate an object with
     the same value (given an appropriate environment). If this
     is not possible, a string of the form "<...some useful
     description...>" should be returned.

     http://pyref.infogami.com/__repr__

</F>




More information about the Python-list mailing list