Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > ``pickling'' and ``unpickling''

Reply
Thread Tools

``pickling'' and ``unpickling''

 
 
sushant.sirsikar@gmail.com
Guest
Posts: n/a
 
      04-06-2006
Hi,
I am new in Python World.I want to know what is mean by ``pickling''
and ``unpickling'' ?
And how can we used it?Please Give Me some links of Picking Examples.
Thanks

Sushant

 
Reply With Quote
 
 
 
 
Lonnie Princehouse
Guest
Posts: n/a
 
      04-06-2006
Pickling is the Python term for serialization. See
http://en.wikipedia.org/wiki/Serialization

Suppose you want to save a Python object "x" to a file...

output_file = open('my_pickle', 'wb') # open a file

import pickle
pickle.dump(x, output_file) # write x to the file
output_file.close()

.... and to restore x from the file:

input_file = open('my_pickle','rb')
x = pickle.load(input_file)
input_file.close()

 
Reply With Quote
 
 
 
 
Roy Smith
Guest
Posts: n/a
 
      04-06-2006
In article < .com>,
"Lonnie Princehouse" <> wrote:

> Pickling is the Python term for serialization. See
> http://en.wikipedia.org/wiki/Serialization
>
> Suppose you want to save a Python object "x" to a file...
>
> output_file = open('my_pickle', 'wb') # open a file
>
> import pickle
> pickle.dump(x, output_file) # write x to the file
> output_file.close()
>
> ... and to restore x from the file:
>
> input_file = open('my_pickle','rb')
> x = pickle.load(input_file)
> input_file.close()


I used to use pickles a lot for making scripts start up faster by cacheing
intermediate results. On startup, I had to read and parse a bunch of large
text files and build a complicated in-memory database out of them. That
took something like 10 seconds. However, the text files very rarely
changed. To save startup time, I read the files in once, and pickled the
database in a file. On subsequent runs, I'd just read in the pickle, which
took a fraction of a second.
 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      04-06-2006
wrote:
> Hi,
> I am new in Python World.I want to know what is mean by ``pickling''
> and ``unpickling'' ?
> And how can we used it?Please Give Me some links of Picking Examples.
> Thanks


You can generally answer such questions yourself by heading to
docs.python.org and typing the relevant words into the conveniently
provided "Search" field in the upper right. With "pickling" the first
result is http://docs.python.org/lib/module-pickle.html which answers
all your questions, including a page of examples.

-Peter

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57