tee chwee liong wrote:
hi,
there is error when running the code:
Traceback (most recent call last):
File "C:/Python25/myscript/log/readfile9.py", line 5, in <module>
port, channel, lane, eyvt = line.split()
ValueError: need more than 2 values to unpack
the error is due to below line code:
port, channel, lane, eyvt = line.split()
pls advise.
You have a line with only 2 words, and you are trying to unpack it into
four variables. Four variables on the left, 4 values on the right works:
>>> a, b, c, d = "sentence with four words".split()
>>> print a
sentence
>>> print b
with
>>> print c
four
>>> print d
words
But 4 variables on the left, 3 on the right does not:
>>> a, b, c, d = "sentence with three".split()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: need more than 3 values to unpack
Likewise:
>>> a, b, c, d = "two words".split()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: need more than 2 values to unpack
>>> a, b, c, d = "word".split()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: need more than 1 value to unpack
--
Steven
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor