[Tutor] (no subject)
Glen Bunting
Glen@ihello-inc.com
Wed, 21 Mar 2001 14:41:11 -0800
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}
but when I do that, only the last values are saved in the dictionary. All
the previous ones are erased.
Glen
-----Original Message-----
From: Deirdre Saoirse [mailto:deirdre@deirdre.net]
Sent: Wednesday, March 21, 2001 2:11 PM
To: Glen Bunting
Cc: 'Daniel Yoo'; 'tutor@python.org'
Subject: RE: [Tutor] (no subject)
On Wed, 21 Mar 2001, Glen Bunting wrote:
> When I make the changes:
>
> >>> import string
> >>> CONFIG = open('webconf.txt').readlines()
> >>> for eachLine in CONFIG:
> ... key, value = string.split(eachLine, ';')
> ... print 'The key is : ', key
> ...
>
> Traceback (innermost last):
> File "<stdin>", line 2, in ?
> ValueError: unpack list of wrong size
>
> What does that mean and what am I doing wrong?
It means that one of your lines doesn't have two elements when split.
You can fix this by:
try:
key, value = string.split(eachLine, ';')
else:
key = eachLine
value = ''
--
_Deirdre NEW Stash-o-Matic: http://fuzzyorange.com http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
- Douglas Adams
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor