Re: "pickle" vs. f.write()

From: Johan Kohler (kohlerj_at_ukzn.ac.za)
Date: 01/26/05


To: "Peter Maas" <peter@somewhere.com>, python-list@python.org
Date: Wed, 26 Jan 2005 15:40:36 +0200

Thanks... works like a charm :-)

On Wed, 26 Jan 2005 12:55:38 +0100, Peter Maas <peter@somewhere.com> wrote:

> Johan Kohler schrieb:
>> class person:
>> name =""
>> age = 0
>> friends=[]
>> comment=""""""
>> me = person()
>> Otherwise, what is the best "Python" way to write and read this data
>> structure?
>
> import pickle
>
> class person:
> name =""
> age = 0
> friends=[]
> comment=""""""
>
> me = person()
>
> # store
> pf = file('/tmp/pickletest', 'w')
> pickle.dump(me, pf)
> pf.close()
>
>
> # load
> pf = file('/tmp/pickletest', 'r')
> me2 = pickle.load(pf)
> pf.close()
>
> This is sequential access. If you want to have random access, look
> for shelve.
>

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
--------------------------------------------------------------------
Please find our disclaimer at http://www.ukzn.ac.za/disclaimer
--------------------------------------------------------------------
<<<<gwavasig>>>>


Relevant Pages