How to make a "command line basd" interactive program?

E

Evan

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
 
M

Matimus

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

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
http://docs.python.org/lib/module-cmd.html

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
http://docs.python.org/lib/module-code.html

example:
.... print "hello, this is foo"
....
Hope this helps,

Matt
 
P

Paddy

that's great, a custom shell is what I need.

Thanks all
Evan

And for the quick-n-dirty there is:
python -i yourscript.py

Which runs your script then drops you into the interpreter.

- Paddy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top