2014-07-03 109 views
0

我收到此錯誤,當我嘗試點擊我的python項目上的按鈕時,它應該返回一個列表, nflgame當你點擊一個按鈕,但是當你點擊按鈕「ValueError:太多值解壓縮」(Python 2.7)

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獨一無二的類,它只是給出了這樣的錯誤:

import sys 
import nflgame 
import nflgame.sched 
from PyQt4 import QtGui 
from window import Ui_Dialog 

class Main(QtGui.QDialog): 
    def __init__(self): 
    QtGui.QDialog.__init__(self) 
    self.ui = Ui_Dialog() 
    self.ui.setupUi(self) 
    self.ui.pushButton.clicked.connect(self.methods) 

    def methods(self): 
    schedule_games = nflgame.sched.games 
    for(y, t, w, h, a), info in schedule_games: 
     if y == 2013 and w == 17: 
      print(' VS. ') 

    team_home = h 
    team_away = a 
    home_game_scores_for = [] 
    away_game_scores_for = [] 
    home_game_scores_against = [] 
    away_game_scores_against = [] 

    gameHOME = nflgame.games_gen(2013, home=team_home, away=team_home, kind='REG') 
    gameAWAY = nflgame.games_gen(2013, home=team_away, away=team_away, kind='REG') 

    for g in gameHOME: 
     if g.home == team_home: 
        home_game_scores_for.append(g.score_home) 
        home_game_scores_against.append(g.score_away) 
     else: 
        home_game_scores_for.append(g.score_away) 
        home_game_scores_against.append(g.score_home) 

    for g in gameAWAY: 
     if g.home == team_away: 
        away_game_scores_for.append(g.score_home) 
        away_game_scores_against.append(g.score_away) 
     else: 
        away_game_scores_for.append(g.score_away) 
        away_game_scores_against.append(g.score_home) 

    self.ui.label.setText("AVG. Points Scored", team_home, round(sum(home_game_scores_for)/float(len(home_game_scores_for)), 1), "VS.", team_away, round(sum(away_game_scores_for)/float(len(away_game_scores_for)), 1)) 
    self.ui.label.setText("AVG. Points Allowed", team_home, round(sum(home_game_scores_against)/float(len(home_game_scores_against)), 1), " VS.", team_away, round(sum(away_game_scores_against)/float(len(away_game_scores_against)), 1)) 

if __name__ == '__main__': 
    app = QtGui.QApplication(sys.argv) 
    window = Main() 
    window.show() 
    sys.exit(app.exec_()) 
+1

「nflgame.sched」模塊是做什麼的? –

+1

我不確定你是否正在使用最新版本的nflgame,但是文檔中提到'nflgame.shed.games'是:「一個有序的日程數據字典,其中的遊戲按照日期排列 以及它們的時間詞典中的鍵是GSIS ID,並且 值是具有以下鍵的詞典:周,月,年, 主頁,離開,星期六,遊戲密鑰,季節類型,時間。「。見https://github.com/BurntSushi/nflgame/blob/master/nflgame/sched.py 也許這對你有幫助嗎? – gurka

回答

0

這個錯誤告訴您名單長度與建議的變量列表不同。嘗試在for循環之前打印列表,您將看到導致錯誤的原因。

您需要在for循環之前將 print(scheduled_games) 。

1

假設正在使用的模塊是the one linked by @gurka,然後schedule_games是一個字典,因此該循環應該被(假設的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. ') 

該文檔不如果年份的值是字符串或數字,如果前者您將不得不使用if int(info['year']) == 2013

相關問題