Re: Persist a class (not an instance)

2005-11-26 Thread Phillip J. Eby
David Wahler wrote: > Kent Johnson 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: > [snip] > > The idea is to persist classes that are created and modified at runtime

Re: Persist a class (not an instance)

2005-11-25 Thread David Wahler
Kent Johnson 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: [snip] > The idea is to persist classes that are created and modified at runtime. I couldn't resist the challenge

Re: Persist a class (not an instance)

2005-11-25 Thread Alex Martelli
Kent Johnson <[EMAIL PROTECTED]> 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 meta

Re: Persist a class (not an instance)

2005-11-25 Thread Sybren Stuvel
Kent Johnson enlightened us with: > OK that confirms that pickle won't work. Is there another approach > that will? Well, since the classes are created at runtime as well, you could compile them using the appropriate API and call exec() on them. Sybren -- The problem with the world is stupidity.

Re: Persist a class (not an instance)

2005-11-25 Thread Kent Johnson
Sybren Stuvel wrote: > Kent Johnson enlightened us with: > >>Is there a way to persist a class definition (not a class instance, >>the actual class) so it can be restored later? > > > From the docs: > > "Similarly, classes are pickled by named reference, so the same > restrictions in the unpick

Re: Persist a class (not an instance)

2005-11-25 Thread Sybren Stuvel
Kent Johnson enlightened us with: > Is there a way to persist a class definition (not a class instance, > the actual class) so it can be restored later? >From the docs: "Similarly, classes are pickled by named reference, so the same restrictions in the unpickling environment apply. Note that none

Persist a class (not an instance)

2005-11-25 Thread Kent Johnson
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: >>> import pickle >>> class Foo(object): ... def show(self): ... print "I'm a Foo" ... >>> p = pickle.dumps(Foo) >>> p 'c__ma