I'm trying to create a dict within a class with keys as prompt-commands and class methods as values, but I'm getting below when trying to run the module
cmd = {'-v': self.view_leagues(),
NameError: name 'self' is not defined
I do not understand why I'm not able to do this?
Example code below:
class CLIStats:
cmd = {'-v': self.view_leagues(),
'exit': 'sys.exit()',
'Back To Home': '-b',
'View Stats Type': '-s',
'Help' : '-h' }
def __init__(self):
self.leagues = {'EN_PR': ['2019/2020', '2018/2019']}
def view_leagues(self):
for league in self.leagues.keys():
print("{: <10}".format(league), end="")
print('\n')
def main():
interface = CLIStats()
print(interface.cmd.keys())
if __name__ == '__main__':
main()