How to make a "command line basd" interactive program?
Cristina Yenyxe González García
the.blue.valkyrie at gmail.com
Fri Apr 11 11:47:25 CEST 2008
2008/4/11, Evan <xdicry at gmail.com>:
> Hope this hasn't been posted hundreds of times. I'm new for this.
> Before using python for this kind of script, I was using TCL to write
> down a "command line based" interactive program. it likes a "tclsh",
> or "python" command, after that, you can work under a prompt, for
> example, " - >> ", and then you can execute any commands what you
> defined in script.
> Now, in python, are there any common way(class) to finish this work?
> or does anybody has a example to do that?
I think the simplest way is using the InteractiveConsole class from the
'code' module. It shows a prompt, reads the commands you type and checks and
executes them. Doc here: http://docs.python.org/lib/module-code.html
This way the TCL part could be not necessary, though.
If you need some special functionality (e.g., storing the commands you
type), you can subclass it easily.
Hope it helps :)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list