eval(repr(x)) == x

Oren Tirosh oren-py-l at hishome.net
Tue Jan 29 03:59:32 EST 2002


On Mon, Jan 28, 2002 at 09:24:17PM -0500, Kragen Sitaker wrote:
> Oren Tirosh <oren-py-l at hishome.net> writes:
> > On Sun, Jan 27, 2002 at 08:33:28AM -0500, François Pinard wrote:
> > > I wonder if `repr' could not be made to produce a string which includes
> > > a non-binary pickle of a complex object, combined with a modification to
> > > the standard Python reading device understanding the convention, and able
> > > to recreate the original from the pickle data in the string.
> > 
> > No need to modify Python for this.  It all depends on you and how you write
> > your object. Just make sure the entire object state can be reconstructed 
> > using the arguments to its constructor and write a __repr__ method that 
> > prints out this constructor call.  As long as your objects are purely
> > hierarchical it can even work recursively.
> 
> That only works for types you write, eh?

It already works for most builtin types (int, str, float, list, tuple, dict).
This was a discussion about how to make it work for user-defined type, too.

The original post of this thread was about whether it should also work for
named objects such as types, classes functions and modules.

	Oren 




More information about the Python-list mailing list