Python's standard library offers a module that encapsulates exactly the "console application that accepts commands" functionality: see https://docs.python.org/3/library/cmd.html .
In that module, the commands are actually methods of your class, which subclasses cmd.Cmd: do_this, do_that, etc, by naming convention. The example at https://docs.python.org/3/library/cmd.html#cmd-example is a rich "console accepting commands" for turtle graphics, so you can play with it.
Didactically, you may want to start with far simpler examples given at http://pymotw.com/2/cmd/ -- that's Python 2 but the functionality is just about the same. The excellent series of examples need a little adaptation to run in Python 3, but it shouldn't be too hard.
For example, consider the very first one:
import cmd class HelloWorld(cmd.Cmd): """Simple command processor example.""" def do_greet(self, line): print "hello" def do_EOF(self, line): return True if __name__ == '__main__': HelloWorld().cmdloop()
The do_EOF is what happens when the user terminates standard input (control-D on Unix); as https://docs.python.org/3/library/cmd.html#cmd.Cmd.cmdloop says,
An end-of-file on input is passed back as the string 'EOF'.
(In this case, the return True terminates the program).
The only thing you need to change to run this in Python 2 rather than 3 is the one line:
print "hello"
which must become
print("hello")
because print, which was a statement in Python 2, is now a function in Python 3.
I find the cmd.py sources at http://www.opensource.apple.com/source/python/python-3/python/Lib/cmd.py to also be quite instructive and I would recommend studying them as an introduction to the world of "dispatching"...!
cmdmodule? I would recommend you using this: docs.python.org/2/library/cmd.htmlargparsedocs.python.org/2/library/argparse.html#module-argparseeval()if all you need to do is dispatch the input.