473,395 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

Jan 30 '07 #1
2 1304
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?

http://www.python.org/doc/current/li...e-example.html

Diez
Jan 30 '07 #2
"raghu" <vg********@gmail.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_reconstructor\np0\n(c__main__\nFoo\np 1\nc__builtin__\nobject\np2\nNtp3\nRp4\n(dp5\nS'ba r'\np6\nI1\nsb."
>>b = pickle.loads("ccopy_reg\n_reconstructor\np0\n(c__m ain__\nFoo\np1\nc__builtin__\nobject\np2\nNtp3\nRp 4\n(dp5\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
http://visenso.com
Jan 30 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Justin Straube | last post by:
Hello, Im trying to compile a script with py2exe. The pickle module is causing the program to give an error. Traceback (most recent call last): File "SETIstat.pyw", line 330, in ? File...
1
by: fanbanlo | last post by:
What seems to be the matter? >>> path = "C:\\eclipse\\workspace\\moin134\\docbook\\xslt\\html\\db_compiled.dat" >>> f = file(path) >>> cPickle.load(f) Traceback (most recent call last):...
14
by: simonwittber | last post by:
I've written a simple module which serializes these python types: IntType, TupleType, StringType, FloatType, LongType, ListType, DictType It available for perusal here: ...
28
by: Grant Edwards | last post by:
I finally figured out why one of my apps sometimes fails under Win32 when it always works fine under Linux: Under Win32, the pickle module only works with a subset of floating point values. In...
0
by: Mike P. | last post by:
Hi all, I'm working on a simulation (can be considered a game) in Python where I want to be able to dump the simulation state to a file and be able to load it up later. I have used the standard...
10
by: crystalattice | last post by:
I'm creating an RPG for experience and practice. I've finished a character creation module and I'm trying to figure out how to get the file I/O to work. I've read through the python newsgroup...
3
by: Jeffrey Barish | last post by:
I have a class derived from string that is used in a pickle. In the new version of my program, I moved the module containing the definition of the class. Now the unpickle fails because it doesn't...
3
by: fizilla | last post by:
Hello all! I have the following weird problem and since I am new to Python I somehow cannot figure out an elegant solution. The problem reduces to the following question: How to pickle a...
10
by: est | last post by:
>>import md5 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python25\lib\pickle.py", line 1366, in dumps Pickler(file, protocol).dump(obj) File...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.