By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

``pickling'' and ``unpickling''

P: n/a
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

Apr 6 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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()

Apr 6 '06 #2

P: n/a
In article <11**********************@i40g2000cwc.googlegroups .com>,
"Lonnie Princehouse" <fi**************@gmail.com> 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.
Apr 6 '06 #3

P: n/a
su**************@gmail.com 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

Apr 6 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.