任何人都可以解释为什么我在return
方法中收到has_happened()
语句的语法错误。
from sys import argv
import time
from datetime import date
class Game(object):
def __init__(self, home, away, home_odds, away_odds, date):
self.home = home
self.away = away
self.home_odds_str = home_odds
self.away_odds_str = away_odds
self.date = date
def to_string(self):
return self.home + ", " + self.away + ", " + self.home_odds + ", " + self.away_odds + ", " + self.result + ", " + self.date
def has_happened(self):
dates_split = self.date.split("/")
today = date.today()
game_date = date(int(dates_split[2]), int(dates_split[1]), int(dates_split[0])
return str(game_date < today)
game1 = Game("t1", "t2", "7/8", "9/1", "29/9/2016")
game1.has_happened()
答案 0 :(得分:0)
def has_happened(self):
dates_split = self.date.split("/")
today = date.today()
game_date = date(int(dates_split[2]), int(dates_split[1]), int(dates_split[0]))
return str(game_date < today)