It's very bad coding practice to mix data and structure like this in general for object oriented programming and Python is no exception. There's a number of ways to solve this:
- you could just passing in the team manager; but it appears that's the step you want to automate
- you could link the Employee to a team instance, something like:
Something like:
class Team:
def __init__(self, name, manager):
self.name = name
self.manager = manager
class Employee:
def __init__(self, name, team):
self.name = name
self.team = team
team_dev = Team("Dev", "Bob")
team_qa = Team("QA", "Kim")
employee_1 = Employee("Jack", team_dev)
print(f'{employee_1.name} is on {employee_1.team.name} as managed by {employee_1.team.manager}')
Note that variables should not be CamelCase, but class names should.
An even nicer solution might be to have the manager of a team be an employee themselves. Of course, then you need the team when you create the employee and the employee when you create the team, so it may need to be None initially:
class Team:
def __init__(self, name, manager=None):
self.name = name
self.manager = manager
class Employee:
def __init__(self, name, team):
self.name = name
self.team = team
team_dev = Team("Dev")
team_dev.manager = Employee("Bob", team_dev)
team_qa = Team("QA")
team_qa.manager = Employee("Kim", team_qa)
employee_1 = Employee("Jack", team_dev)
print(f'{employee_1.name} is on {employee_1.team.name} as managed by {employee_1.team.manager.name}')
self.Manger&self.Managerdifferent variables? Or its a typo?