J
Johan Kohler
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..
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..