In my Python project I'm trying to make the interface somewhat like a command prompt where I can type the name of a function and it will be executed. Example:
Prompt >>> run.check
Running function check....
Prompt >>> run.get
Running function get
In the above example when I type run.check it should run a function named check and run.get should run function get and so on.
Right now I have a prompt using raw_input and I can execute commands by using a dictionary of function alias' and function names ie,
COMMANDS = {'exit': sys.exit,
'hello': greet,
'option3': function3,
'option4': function4,
}
cmd = raw_input("Prompt >>> ")
COMMANDS.get(cmd, invalidFunction)()
But a lot of the functions in my programs needs arguments to be passed to it which I do not know how to do with this method. Another thing is that, the main purpose of my project is for modules (.py files) to be added to a folder and then executed dynamically with the main python program using the command prompt like interface and I would like to do this with minimum if possible no change to the main program.
I'm not sure of using the function exec as it has some drawbacks concerning security.
Thank You.
X
modules). Wouldn't it be the same amount of work to writeX
checks to only allow those specificX
functions to be processed usingexec
.