Writing dictionary output to a file

simon place simon_place at whsmithnet.co.uk
Sat Mar 6 13:53:57 CET 2004

i use this to save and reload a dict, slower than pickling but you get a human 
readable file and its soooo simple.

 >>> a
{1: 'one', 2: 'two'}

# to save to dict.txt
 >>> print >>file('dict.txt','w+'),str(a)

# to reload
 >>> exec('b=dict('+file('dict.txt','r').read()+')')

 >>> b
{1: 'one', 2: 'two'}

More information about the Python-list mailing list