reading files into dicts

Tim Williams (gmail) tdwdotnet at gmail.com
Thu Dec 29 20:22:11 EST 2005


Apologies for the top post, it was my first attempt at using gmail's
pda-enabled web interface. There is no option to bottom post.

Apart from the mistake in my previous reply, when I meant to suggest
using import instead of eval() not repr(). I also omitted an example.
So here goes -but I don't know how gmail-CE will format this!!

Save your dict to a file  with a .PY extension using

outdata = 'mydict =' + repr(dict) # or somesuch
 similar

dictfile.py
-----------------------
mydict = {'key1':'a', 'key2':'b'}
-----------------------

Then:

import dictfile
print dictfile.mydict.keys()
>>>['key1','key2']
reload(dictfile)

HTH :-)

--

Tim Williams



More information about the Python-list mailing list