“ValueError:太多的值无法解包”(Python 2.7)

2024-10-17 00:30:31 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试在python项目中单击按钮时,会得到一个错误,当您单击按钮时,它应该返回一个使用名为nflgame的包的每场游戏的平均得分列表,但是当您单击按钮时,它只会给出这个错误

Traceback (most recent call last):
File "C:\Users\Developer\workspace2\test2\main.py", line 16, in methods
for(y, t, w, h, a), info in schedule_games:
ValueError: too many values to unpack

这里是除了GUI之外我唯一拥有的类:

^{pr2}$

Tags: 项目in游戏developermost列表错误call
2条回答

假设您使用的模块是the one linked by @gurka,那么{}是一个字典,所以循环应该是(假设Python 3.x,而不是2.x):

for gsis_id, info in schedule_games.items():
    # info is itself a dict with keys: 
    #    week, month, year, home, away, wday, gamekey, season_type, time
    if info['year'] == 2013 and info['week'] == 17:
        print(' VS. ')

文档没有说明year的值是字符串还是数字,如果是前者,则必须使用if int(info['year']) == 2013。在

此错误说明列表的长度与建议的变量列表不同。尝试在for循环之前打印列表,您将看到导致错误的原因。在

你需要把 打印(预定游戏) 就在for循环之前。在

相关问题 更多 >