command parsing and interpreter interaction

Chad Everett chat at linuxsupreme.homeip.net
Fri May 18 19:12:36 CEST 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
3
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
argument
mycmd_prompt> mycommand2 arg1	# another of my commands interpreted by cmd


Anyone know of a way to do this?

Thanks,

Chad





More information about the Python-list mailing list