pickle

Shi Mu samrobertsmith at gmail.com
Tue Oct 25 03:23:23 EDT 2005


what does the following code mean?

y = pickle.load(file("cnumber.pickle", "r"))

also, I can not understand "f" in pickle.dump(x, f)

On 10/25/05, marduk <usenet at marduk.letterboxes.org> wrote:
> 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