[Tutor] (no subject)

Kalle Svensson kalle@gnupung.net
Wed, 21 Mar 2001 23:18:26 +0100


Sez Glen Bunting:
> 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?

There is more than one ";" in the line, so string.split returns more than
two elements.  But you try to assign them to key, value.  Only two elements.
There are many ways to solve it.  For example, try:

import string
CONFIG = open('webconf.txt').readlines()
for eachLine in CONFIG:
    elements = string.split(eachLine, ';')
    print 'The key is : ', elements[0]    # the first element
    print 'The rest is : ', elements[1:]  # the rest

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. ]