pickle

marduk usenet at marduk.letterboxes.org
Tue Oct 25 03:04:23 EDT 2005


On Mon, 2005-10-24 at 23:55 -0700, Shi Mu wrote:
> I got a sample code and tested it but really can not understand the
> use of pickle and dump:
> 
> >>> import pickle
> >>> f = open("try.txt", "w")
> >>> pickle.dump(3.14, f)
> >>> pickle.dump([1,2,3,4], f)
> >>> f.close()

The pickle module "serializes" python objects.  You can "dump" a python
object that can later be loaded:

>>> x = complex(2,3.5)
>>> f = open("cnumber.pickle", "w")
>>> import pickle
>>> pickle.dump(x, f)
>>> f.close()
>>> y = pickle.load(file("cnumber.pickle", "r"))
>>> y
(2+3.5j)





More information about the Python-list mailing list