Explanation about pickle module

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

    #1

    Explanation about pickle module

    can any one explain about pickle i read in the book but they have not
    provided any example for that so please explain with a simple example

  • Diez B. Roggisch

    #2
    Re: Explanation about pickle module

    raghu wrote:
    can any one explain about pickle i read in the book but they have not
    provided any example for that so please explain with a simple example
    Bad google day? Or just to lazy to do it? And what is "the book"? There are
    quite a few out there, some about python the language, others about snakes
    of the same name. Which one?



    Diez

    Comment

    • Marco Wahl

      #3
      Re: Explanation about pickle module

      "raghu" <vgvr620034@gma il.comwrites:
      can any one explain about pickle i read in the book but they have not
      provided any example for that so please explain with a simple example
      >
      >>class Foo(object):
      .... def __init__(self):
      .... self.bar = 1
      ....
      >>import pickle
      >>a = Foo()
      >>pickle.dumps( a)
      "ccopy_reg\n_re constructor\np0 \n(c__main__\nF oo\np1\nc__buil tin__\nobject\n p2\nNtp3\nRp4\n (dp5\nS'bar'\np 6\nI1\nsb."
      >>b = pickle.loads("c copy_reg\n_reco nstructor\np0\n (c__main__\nFoo \np1\nc__builti n__\nobject\np2 \nNtp3\nRp4\n(d p5\nS'bar'\np6\ nI1\nsb.")
      >>b.bar
      1
      >>b
      <__main__.Foo object at 0x402ae68c>
      >>>
      There is also pickle.dumps and pickle.loads to work
      directly with files. Further there is module cpickle
      which offers the same functionality as pickle but which
      is faster.


      Bye
      --
      Marco Wahl

      Comment

      Working...