473,796 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

``pickling'' and ``unpickling''

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
3 3612
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.clo se()

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

input_file = open('my_pickle ','rb')
x = pickle.load(inp ut_file)
input_file.clos e()

Apr 6 '06 #2
In article <11************ **********@i40g 2000cwc.googleg roups.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.clo se()

... and to restore x from the file:

input_file = open('my_pickle ','rb')
x = pickle.load(inp ut_file)
input_file.clos e()


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1740
by: Bob | last post by:
I've read over section 3.14.5.2 of the doc about a zillion times, and it still makes absolutely no sense to me. Can someone please explain it? What I'd like to do is, basically, have the object be pickled as None, since it represents an object in the C world, and it doesn't make sense to pickle it at all. How can I do that, if at all? In particular, what does this
1
1533
by: Thomas Guettler | last post by:
Hi! After unpickling the objects are not the same any more. Is this a bug or feature? import pickle class MyDictContainer(dict): def __init__(self): dict.__init__(self)
1
2333
by: Marc | last post by:
Hi all, After some research I've decided that my previous question (Confusing problem between Tkinter.Intvar...) was headed in the wrong direction. Partly because I think I have a greater understanding of what was happening, and partly because pickling Tkinter widgets is an issue that seems to have been touched on over the years but never really acted on. Postings back to '96 have talked about the need to pickle Tk widgets.
1
1379
by: Pekka Niiranen | last post by:
Hi there, why must file be opened in "r" -mode, before loading works with Pickling? This forces me to close the file between pickle.dump and pickle.load. :( Example: -----************------ a = {'pekka': 1, 'jussi': 2}
176
8194
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? Thank you, -- greetz tom
1
3262
by: fedor | last post by:
Hi all, happy new year, I was trying to pickle a instance of a subclass of a tuple when I ran into a problem. Pickling doesn't work with HIGHEST_PROTOCOL. How should I rewrite my class so I can pickle it? Thanks , Fedor
1
2281
by: Erik Max Francis | last post by:
I've come across a limitation in unpickling certain types of complex data structures which involve instances that override __hash__, and was wondering if it was known (basic searches didn't seem to come up with anything similar) and if there is a workaround for it short of restructuring the data structures in question. The fundamental issue rests with defining classes which override __cmp__ and __hash__ in order to be used as keys in...
0
1278
by: Shahin Saadati | last post by:
Hi, The following sample code is to pickle and unpickle an object. It works fine with CPython, but the unpickling fails in Jython and I receive an error stating that "A" is unsafe to unpickle (even though I believe I have the code to make "A" safe for unpickling). What do I do wrong and how can I fix it? Thanks, ============================================== import sys
9
3602
by: Alex | last post by:
I have a serious problem and I hope there is some solution. It is easier to illustrate with a simple code: >>> class Parent(object): __slots__= def __init__(self, a, b): self.A=a; self.B=b def __getstate__(self): return self.A, self.B def __setstate__(self, tup):
0
9531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.