Newbie query - reading text file (with column headings) into dictionary

Andy Elvey andy.elvey at paradise.net.nz
Sat Dec 7 18:44:42 EST 2002


Hi all.
  I have a text file (comma separated) which looks like this -
 Country, City,  Var1, Var2, Var3
 Australia, Sydney, 123,456,789
 Australia, Perth, 415, 201, 142
 .... and so on.
( Btw- I'm running Python 2.2 on Win98 )
  I want to read the file into a dictionary so that the column headings
(Country, city ,... ) are the keys, and the rest of the file is slotted into
the appropriate key ( so that "Australia" has "Country" as the key, "Sydney"
and "Perth" have "City" as the key, and so on.  This must be quite
straightforward to do, but searching the 'net (including the Python Cookbook
site) turns up nothing along these lines .... So - any help is very much
appreciated.
 (Oh - and the solution to this would be very useful to have on the "Python
Cookbook" site .... :-)  Thanks in advance ...






More information about the Python-list mailing list