Reputation: 61
s = ('con', 'str', 'wit', 'int', 'dex', 'mp', 'p.def', 'm.def', 'p.atack', 'm.atack')
c.execute("SELECT con, str, wit, _int, dex, mp, mdef, pdef, patack, matack FROM warrior_stat")
t = c.fetchone()[:]
for s1, t1 in s, t: print "%020s, " - ", %010s, '\n'" % (s, t)
Why do I have this error:
Traceback (most recent call last):
File "./test.py", line 49, in <module>
for s1, t1 in s, t: print "%020s, " - ", %010s, '\n'" % (s, t)
ValueError: too many values to unpack
How can I fix it?
thanks for all comments !!! i am printing %(s, t) instead (s1, t1) and zip(s, t) worked correctly after this corection
dont make +1 into reputation. but my reputation is low
Upvotes: 0
Views: 1573
Reputation: 4182
I think there should be single quotes inside
print "%020s, " - ", %010s, '\n'" % (s, t)
In this case only second part of string is formatted
", %010s, '\n'" % (s, t)
And here as You can see only one place holder for value but 2 value is passed So this is incorrect.
and I don't know why \n
is quoted.
It seems that this line should be following:
print "%020s - %010s, \n" % (s, t)
Upvotes: 2
Reputation: 28259
you need to zip two lists, and it should be in one string:
for s1, t1 in zip(s, t):
print "%020s - %010s \n" % (s, t)
Upvotes: 0
Reputation: 91017
To be strict, your 2nd problem would probable be worth opening another question, because now you have a problem elsewhere.
With
print "%020s, " - ", %010s, '\n'" % (s, t)
you apply the %
operation to ", %010s, '\n'"
, which is clearly not correct.
Even if it was, you'd get another error: you try to subtract the resulting string from "%020s, "
which doesn't work as well.
Try
print "%020s - %010s" % (s, t)
Upvotes: 0