"pickle" vs. f.write()

Johan Kohler kohlerj at ukzn.ac.za
Wed Jan 26 05:16:01 EST 2005


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>>>>



More information about the Python-list mailing list