"pickle" vs. f.write()
From: Johan Kohler (kohlerj_at_ukzn.ac.za)
Date: 01/26/05
- Next message: Premshree Pillai: "Re: python without OO"
- Previous message: Thomas Heller: "Re: py2exe problem"
- Next in thread: Peter Maas: "Re: "pickle" vs. f.write()"
- Reply: Peter Maas: "Re: "pickle" vs. f.write()"
- Maybe reply: Terry Reedy: "Re: "pickle" vs. f.write()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 26 Jan 2005 12:16:01 +0200 To: python-list@python.org
Hi,
I have a class with attributes that are string, integer and list. eg.
class person:
name =""
age = 0
friends=[]
comment=""""""
me = person()
I want to save a whole bunch of instances to a file, a classic "records"
file I/O.
To write the file, I can do f.write(str([me.name, me.age, me.friends,
me.comment]) + "\n"
This works nicely for writing, but when reading, I cannot convert the
string easily to a list:
list(f.readline()) is not the same as [me.name, me.age, me.friends,
me.comment]
I was wondering whether pickle might make this easier - an example would
be much appreciated.
Otherwise, what is the best "Python" way to write and read this data
structure?
Thanks in advance...
Johan
__
Yes, I do feel stupid asking this, but time's-a-runnin' out..
-- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/ -------------------------------------------------------------------- Please find our disclaimer at http://www.ukzn.ac.za/disclaimer -------------------------------------------------------------------- <<<<gwavasig>>>>
- Next message: Premshree Pillai: "Re: python without OO"
- Previous message: Thomas Heller: "Re: py2exe problem"
- Next in thread: Peter Maas: "Re: "pickle" vs. f.write()"
- Reply: Peter Maas: "Re: "pickle" vs. f.write()"
- Maybe reply: Terry Reedy: "Re: "pickle" vs. f.write()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|