Persist a class (not an instance)

Alex Martelli aleax at
Fri Nov 25 18:30:00 CET 2005

Kent Johnson <kent37 at> wrote:

> Is there a way to persist a class definition (not a class instance, the
> actual class) so it can be restored later? A naive approach using pickle
> doesn't work:

You can use copy_reg to customize pickling behavior.  In this case,
you'd need a custom metaclass to use as the type for your "picklable
classes".  Moreover, if the class has attributes that you also want to
pickle, such as methods or properties, you'll have to arrange for custom
pickling of *them*, too.  So, yes, there are ways, but not simple ones.


More information about the Python-list mailing list