cannot pickle object returned by urllib2.urlopen()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • scsoce

    cannot pickle object returned by urllib2.urlopen()

    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 ?

  • Steven D'Aprano

    #2
    Re: cannot pickle object returned by urllib2.urlopen ()

    On Wed, 12 Nov 2008 11:00:26 +0800, scsoce wrote:
    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.



    --
    Steven

    Comment

    • greg

      #3
      Re: cannot pickle object returned by urllib2.urlopen ()

      On Wed, 12 Nov 2008 11:00:26 +0800, scsoce wrote:
      >
      >>got a exception: "a class that defines __slots__ without defining
      >>__getstate_ _ cannot be pickled "
      >>why?
      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.

      --
      Greg

      Comment

      Working...