On Apr 11, 2:32 am, Evan <xdi...@gmail.c omwrote:
Do you want a custom shell that does whatever you want? Or do you want
an interactive python shell that has some custom commands?
For the first check out the cmd module
example:
.... def do_echo(self, params):
.... print params
....
(Cmd) echo Hello World
Hello World
(Cmd) help
Undocumented commands:
=============== =======
echo help
For the second, check out the code module
example:
.... print "hello, this is foo"
....
Welcome to my python shell!
hello, this is foo
Hope this helps,
Matt
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?
>
Thanks,
Evan
>
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
example:
>>import cmd
>>class MyCmd(cmd.Cmd):
>>class MyCmd(cmd.Cmd):
.... print params
....
>>MyCmd().cmdlo op()
Hello World
(Cmd) help
Undocumented commands:
=============== =======
echo help
For the second, check out the code module
example:
>>import code
>>def foo():
>>def foo():
....
>>code.interact ("Welcome to my python shell!", local={'bar':fo o})
>>bar()
>>>
Matt
Comment