0
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

4

3 回答 3

2

我认为里面应该有单引号

print "%020s, " - ", %010s, '\n'" % (s, t)

在这种情况下,只有字符串的第二部分被格式化

", %010s, '\n'" % (s, t)

在这里,您只能看到一个占位符的值,但传递了 2 个值所以这是不正确的。

我不知道为什么\n被引用。这条线似乎应该如下:

print "%020s -  %010s, \n" % (s, t)
于 2013-10-22T09:22:45.637 回答
0

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)
于 2013-10-22T09:43:30.907 回答
0

你需要压缩两个列表,它应该在一个字符串中:

for s1, t1 in zip(s, t):
    print "%020s - %010s \n" % (s, t) 
于 2013-10-22T09:25:40.333 回答