eval(repr(object)) hardly ever works

sjdevnull at yahoo.com sjdevnull at yahoo.com
Wed Sep 13 15:43:02 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.

Just to reinforce something Skip mentioned:

If you're looking for a way to serialize an object into a string, and
then later turn that string back into an object, you probably want the
pickle module (the marshal module is similar but is really intended for
internal use; unless you know exactly why you're picking one over the
other, using pickle is probably the right call).

http://docs.python.org/lib/module-pickle.html




More information about the Python-list mailing list