"pickle" vs. f.write()

Johan Kohler kohlerj at ukzn.ac.za
Wed Jan 26 08:40:36 EST 2005


Thanks... works like a charm :-)

On Wed, 26 Jan 2005 12:55:38 +0100, Peter Maas <peter at 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>>>>



More information about the Python-list mailing list