command parsing and interpreter interaction

Chad Everett chat at
Fri May 18 13:12:36 EDT 2001

I want to build a set of commands in the same way that the Cmd
module allows one to do, but I want all lines entered at the
prompt that are not defined by my interpreter to be handled
by python as if it had been entered at the python interactive
interpreter prompt.

For example:

mycmd_prompt> mycommand arg1 arg2 arg3   # defined & handled by my cmd instance
mycmd_prompt> a = 3                # not defined by my cmd instance
mycmd_prompt> a                    # so the python interpreter handles it
mycmd_prompt> def myfunc( myarg ): # python handles this 
...               # this is a function def handled by python
...               print myarg
mycmd_prompt> myfunc('argument')   # handled by python's interpreter
mycmd_prompt> mycommand2 arg1	# another of my commands interpreted by cmd

Anyone know of a way to do this?



More information about the Python-list mailing list