를 업데이트하려면
from collections import namedtuple
HalfTime = namedtuple('Halftime', 'goals yellow_cards')
my_match.half_time = HalfTime(4, 5)
my_match.half_time.goals
>>> 4
my_match.half_time.yellow_cards
>>> 5
은 당신이 묘사하는 것은 통계의 세트와 일치의 다른 기간에 대한 통계 별도의 세트를 유지하고있다.
별도의 통계 클래스로이를 구현하고 전체 경기에 대한 통계를 누적하는 하나의 인스턴스를 포함하여 경기의 다른 기간 동안 해당 클래스의 여러 인스턴스를 보유하게됩니다. 다음과 같은 내용 일 수 있습니다.
class Statistics(object):
def __init__(self):
self.__goals = 0
self.__yellow_cards =0
def getGoals(self): return self.__goals
def addGoal(self): self.__goals += 1
…
class AccumulatedStatistics(object):
def __init__(self, *statistics):
self.__statistics = list(statistics)
def getGoals(self):
return reduce(lambda a,b:a.getGoals() + b.getGoals(), statistics)
…
class Match(object):
def __init__(self):
self.quarterStats = [Statistics(), Statistics(), Statistics(), Statistics()]
self.halfStats = [
AccumulatedStatistics(self.quarterStats[0], self.quarterStats[1]),
AccumulatedStatistics(self.quarterStats[2], self.quarterStats[3]),
]
self.matchStats = AccumulatedStatistics(*self.quarterStats)
이것은 너무 광범위합니다. –