Definition of 'pickle'

Jay Dorsey python at jaydorsey.com
Wed May 28 08:19:39 EDT 2003


Basically, pickling allows you to take a complex data type such as a 
dictionary, array, list, or tuple (for example), and store that information 
in a byte stream which can then be written to a file.  When you "unpickle" 
that stream, you have the complex data type, not just a text representation 
of it.

ColdFusion (my day job, sorry :p ) has a similar function which uses WDDX ('an 
XML-based technology that enables the exchange of complex data betwen web 
programming languages' - www.openwddx.org) to store the data in.  With WDDX, 
you can create an associative array in ColdFusion, convert it (serialize), 
save it to a file, then take any other language that supports WDDX (let's 
say, PHP), open that file up, deserialize it, and have an associative array 
in that language.  Unfortunately I'm not familiar enough with pickle to say 
whether its the same format as WDDX or not.

Simple example:

>>> import pickle
>>> x = []
>>> x.append('a')
>>> x.append('b')
>>> x
['a', 'b']
>>> type(x)
<type 'list'>
>>> pickle.dump(x, file('pick.p', 'w')) # creates a file, pick.p
>>> z = pickle.load(file('pick.p', 'r'))
>>> z
['a', 'b']
>>> type(z)
<type 'list'>

hth

jay




On Wednesday 28 May 2003 07:59, anson wrote:
> Dear people,
>
> I don't understand the definition provided in the Python documentation
> for 'pickle':
>
> The pickle module implements a fundamental, but powerful algorithm for
> serializing and de-serializing a Python object structure. ``Pickling''
> is the process whereby a Python object hierarchy is converted into a
> byte stream, and ``unpickling'' is the inverse operation, whereby a
> byte stream is converted back into an object hierarchy. Pickling (and
> unpickling) is alternatively known as ``serialization'',
> ``marshalling,''3.2 or ``flattening'', however the preferred term used
> here is ``pickling'' and ``unpickling'' to avoid confusing.
>
> thanks!
>
> zeallous

-- 
Jay Dorsey
python at jay dorsey dot com






More information about the Python-list mailing list