The best way would be to use dictionaries.
teams = {
'Burnley': team("Burnley",[1, 0, 0, 1], True),
'Southampton': team("Southampton", [1,2,1,0,0,0,1], True),
'Swansea': team("Swansea",[1,2,1,1,1,2,1,1,0,0,0,0,0,0,3], True)
}
# and then simply fetch values from it
Burnley = teams['Burnley']
...
for idx, game in df.iterrows():
home_team_name = game["HomeTeam"] # Burnley let's assume
home_team = teams[home_team_name]
...
BUT, if you really want what the question asks for, keep reading.
Let's say I have a file, sample.py
# sample.py
from pprint import pprint
variable = 'some value'
x = 20
pprint(globals())
Output:
$ python3 sample.py
{'__annotations__': {},
'__builtins__': <module 'builtins' (built-in)>,
'__cached__': None,
'__doc__': None,
'__file__': 'sample.py',
'__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7fccad01eb80>,
'__name__': '__main__',
'__package__': None,
'__spec__': None,
'pprint': <function pprint at 0x7fccacefdf70>,
'variable': 'some value',
'x': 20}
As you can see, all variables defined will be added to globals()
and it's a dict
, which means you can get the values from it.
Therefore you can do something like this
# sample.py
variable = 'some value'
x = 20
variable_name = 'variable'
number_name = 'x'
value_of_variable = globals().get(variable_name)
print(f'Value of variable = {value_of_variable}')
value_of_x = globals().get(number_name)
print(f'Value of x = {value_of_x}')
Output:
Value of variable = some value
Value of x = 20
So for your case,
...
for idx, game in df.iterrows():
home_team_name = game["HomeTeam"] # Burnley let's assume
home_team = globals().get(home_team_name) # would give you the value of the variable `Burnley` if it exists
...
If you've read the entire answer up to here, as a suggestion I'd like to add that class names should begin with a capital letter. class Team:
instead of class team: