eval(repr(x)) == x

François Pinard pinard at iro.umontreal.ca
Sun Jan 27 11:27:39 EST 2002


[Oren Tirosh]

> 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

> No need to modify Python for this.  It all depends on you and how you write
> your object.

One then needs to write `__repr__' for each object.  I meant a default
for all objects, Python wide.  Currently, the default `__repr__' writes
the class name and the in-memory address, which hints the user about the
object class and whether if two objects are identical or different.

> > Yes, it traversed my mind that `repr' of a complex object, containing
> > a representation of it, could use a lot of characters, maybe enough to
> > kill legibility.  I was probably hoping a miracle :-).  Some happen!

> C'est un miracle! The pprint module!

I was hoping the miracle that `__repr__' could print a reasonable-sized
string, not giving the user the impression of clutter, in such a way that
it could be read back.

But it is just not possible in practice.  Suffice to have many object
variables, or any sequence or map which is not small, that you necessarily
get a lot of characters in any reversible representation of an object.

> I don't think repr can be or should be a general purpose replacement for 
> pickling, but there are some places where it can serve a similar function.

My feeling as well.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Python-list mailing list