Hope this hasn't been posted hundreds of times. I'm new for this.Do you want a custom shell that does whatever you want? Or do you want
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?
Thanks,
Evan
an interactive python shell that has some custom commands?
For the first check out the cmd module
http://docs.python.org/lib/module-cmd.html
example:
.... def do_echo(self, params):>>import cmd
class MyCmd(cmd.Cmd):
.... print params
....
(Cmd) echo Hello World>>MyCmd().cmdloop()
Hello World
(Cmd) help
Undocumented commands:
======================
echo help
For the second, check out the code module
http://docs.python.org/lib/module-code.html
example:
.... print "hello, this is foo">>import code
def foo():
....
Welcome to my python shell!>>code.interact("Welcome to my python shell!", local={'bar':foo})
hello, this is foo>>bar()
Hope this helps,>>>
Matt