[Tutor] (no subject)
Kalle Svensson
kalle@gnupung.net
Wed, 21 Mar 2001 23:58:53 +0100
Sez Glen Bunting:
> Thanks, now that I've got that figured out, how do I put teh values key and
> value into a dictionary.
>
> >>> import string
> >>> dict {}
> >>> CONFIG = open('webconf.txt').readlines()
> >>> for eachLine in CONFIG:
> ... key, value = string.split(eachLine, ';')
> ... dict = {key, value}
Try dict[key] = value on the last line.
> but when I do that, only the last values are saved in the dictionary. All
> the previous ones are erased.
That's because your code binds a new dictionary (created by {key, value})
to the variable dict each time through the loop.
More about dictionaries:
http://www.python.org/doc/current/lib/typesmapping.html
Hope I'm right this time...
Peace,
Kalle
--
Email: kalle@gnupung.net | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
[ Not signed due to lossage. Blame Microsoft Outlook Express. ]