Naming dictionaries recursively

TYR a.harrowell at gmail.com
Fri Aug 17 08:38:16 EDT 2007


I'd like to do something like this; iterate through a file which
consists of data stored in dictionary format, one dict on each line,
and read each line into a new dict using one of the values in the dict
as its name...

for example:

stuff = open('data.txt')
 for eachLine in stuff:
  name{}
   name = eachLine
....and then do something clever to extract the value of the key
(name) from the line and use it as the dictionary's name.

A line from data.txt would look like this: {'name' : Bob, 'species' :
Humboldt, 'colour' : red, 'habits' : predatory}. Aim is to call one of
them by name, and merge the values in that dictionary into a string
pulled from another source.




More information about the Python-list mailing list