469,328 Members | 1,280 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

Pickling a class instead of an instance

Hi,

It seems to me that it's not possible with the pickle module
to serialize a class rather than an instance, as in
from pickle import *

class C(object):
"... doc ..."
a = 1

pickstr = dumps(C)


I mean, it does *something*, there is no error indeed, but
from the string pickstr, I am unable to rebuild the class
C in a brand new context (got a "you're really stupid, all
you deserve is an AttributeError because you know there is
no attribute 'C' in the 'module' object" error).

Am I wrong ? Why would the "(new-style) classes are regular
objects too" mantra not apply in this case ? Could we imagine
a patch to the pickle module to handle this kind of situation ?

SB
Jul 18 '05 #1
1 889
have a look at the thread "copying classes?" some days ago.
what goes for copying goes for pickling also, because the
modules use the same interface.

- harold -

On 13.01.2005, at 13:32, Sebastien Boisgerault wrote:
Hi,

It seems to me that it's not possible with the pickle module
to serialize a class rather than an instance, as in
from pickle import *

class C(object):
"... doc ..."
a = 1

pickstr = dumps(C)


I mean, it does *something*, there is no error indeed, but
from the string pickstr, I am unable to rebuild the class
C in a brand new context (got a "you're really stupid, all
you deserve is an AttributeError because you know there is
no attribute 'C' in the 'module' object" error).

Am I wrong ? Why would the "(new-style) classes are regular
objects too" mantra not apply in this case ? Could we imagine
a patch to the pickle module to handle this kind of situation ?

SB
--
http://mail.python.org/mailman/listinfo/python-list

--
If you make people think they're thinking, they'll love you;
but if you really make them think they'll hate you.

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Edward Loper | last post: by
reply views Thread by Skip Montanaro | last post: by
8 posts views Thread by Hans Georg Krauthaeuser | last post: by
1 post views Thread by fedor | last post: by
2 posts views Thread by Kirk Strauser | last post: by
1 post views Thread by Erik Max Francis | last post: by
reply views Thread by jeanphilippe.aumasson | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.