[Python-Dev] pickle me, Elmo?

Guido van Rossum guido@python.org
Mon, 10 Feb 2003 12:21:22 -0500


> I read the new PEP about pickling with much interest and little
> comprehension. I'd like to comment then just by saying what I wish I could
> do and invite response as to whether the PEP will help do it.
> 
> I would like to be able to:
> 
> Save and restore a class definition
> Save and restore a function definition

Alas, that ground is specifically not covered by pickling -- not in
the past and not now.  This is by design.  Pickling was designed for
data, and when the data contains a reference to a class or function,
that reference is specifically excluded from the pickling; instead,
the pickler says "here's a reference to class C (or function f) in
module M"; the unpickler imports module M, finds C or f in it, and
inserts that in the unpicked data.

But you're not the only one to want to save and restore classes and
functions.

Jeremy Hylton has gone through heroic efforts to make this possible in
Zope 3, by subclassing the Pickler and Unpickler classes.  Maybe he
can tell you more.

--Guido van Rossum (home page: http://www.python.org/~guido/)