cannot pickle object returned by urllib2.urlopen()

S

scsoce

got a exception: "a class that defines __slots__ without defining
__getstate__ cannot be pickled "
why?
and is there any other dump method but for pickle to store the kind of
object ?
 
S

Steven D'Aprano

got a exception: "a class that defines __slots__ without defining
__getstate__ cannot be pickled "
why?
and is there any other dump method but for pickle to store the kind of
object ?

I can't answer either of your questions, but why are you trying to pickle
an open connection to a (possibly remote) URL? I can't imagine how that
could possibly work even in principle.
 
G

greg

Because in the absence of any other information, the default
way of pickling an object is to save the contents of its
__dict__. But an object with __slots__ doesn't necessarily
have a __dict__, and even if it does, it doesn't include
the contents of the slots. So you need to tell pickle how to
deal with it by defining __getstate__ and __setstate__ methods.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,099
Latest member
AmbrosePri
Top