In the application I'm currently working on, i want to include a feature in which the administrator has access to a sort of command line.
This is not the actual command line, instead it looks for keywords inside a Textbox that I define, and runs their linked functions with the input parameters.
For instance:
get user data: erikthered
...would run the method self.user_data('erikthered'), but I'm unsure how to get to this step elegantly, without using messy things like eval or exec.
These features should ideally also work for multiple parameters.
I apologise if this question is considered subjective, but I haven't really programmed something like this before, and I value other people's insights.
Thanks
UPDATE
One way to do this, using exec, is to use a dictionary, like so:
links = {'get users':'self.get_users(parameters)', 'get user data':'self.get_user_data(parameters)'}
terminal = self.terminal
line = str(terminal.index(INSERT).split('.')[0])
#get index of line
line = terminal.get(line+'.0', line+'.end')
splitline = line.split(':')
command = splitline[0]
parameters = splitline[1].split(',')
exec(links[command])
This is the code I have to get the text that the user has typed, bound to a return press. But I would prefer not to use exec.