My issue here is with calling classes inside another class. Independently, I can set this up how I want the 2 classes to work. I just cannot get them working together. I want my dataset (which is football fixtures and results) to be passed to a class League, which holds all the league info and then every team inside that league is inside the class Team which is a child of the parent class League. Example shows just a snippet of how this is set up
At the bottom of the example you will see the function 'total_attack_strength_home(self):' Here I need to access the class Team, but then the last part of the calculation references the respective class object (The league that the club sits in). Any help on this would be appreciated. Thanks
'''
class League():
def init(self,league):
self.league = league
self.total_goals_scored = self.get_total_goals_scored()
self.home_goals_scored = self.get_home_goals_scored()
def get_total_goals_scored(self):
pass
def get_home_goals_scored(self):
pass
class Team(League):
def init(self,club):
self.club = club
self.home_wins = self.get_home_wins()
self.home_draws = self.get_home_draws()
def total_attack_strength(self):
if len(self.total_goals) == 0:
attack_strength = 0
else:
attack_strength = (sum(self.total_goals) / len(self.total_goals)) / ***(total_goals_scored/games_played)***
return attack_strength'''
Teamto be a subclass ofLeague. A Team is not itself also a League. You probably want to use "composition" here rather than inheritance.super()function. There's a lot to read, too much to explain here. Also, yourinit()function should usesuper()to invoke the baseclass'init().superis irrelevant, becauseTeamshould not be inheriting fromLeagueat all. A league is a collection of teams. Both methods inLeagueshould be defined inTeam.