Lists and Files
Steve Purcell
stephen_purcell at yahoo.com
Mon Mar 26 10:04:34 EST 2001
David Andreas Alderud wrote:
> I'm new to Python, started yesterday, is there a good way to handle lists
> and files?
>
Try the 'pickle' module:
>>> import pickle
>>> stooges = ['val1', 'val2', 1, [['val2_1', 'val2_2', 0], ['val2_1',
... 'val2_2', 0]]]
>>> save_file = 'stooges.dat'
>>> output = open(save_file,'wb')
>>> pickle.dump(stooges, output)
>>> output.close()
>>> input = open(save_file,'rb')
>>> stooges2 = pickle.load(input)
>>> input.close()
>>> stooges2
['val1', 'val2', 1, [['val2_1', 'val2_2', 0], ['val2_1', 'val2_2', 0]]]
-Steve
--
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo
More information about the Python-list
mailing list