Q: Interactive input
Kalle Svensson
kalle at gnupung.net
Tue Oct 24 10:53:01 EDT 2000
On 24 Oct 2000, Jan Kybic wrote:
> Hi,
> would there be a simple way to stop the execution of a script,
> read commands from the keyboard and execute them in the current
> frame? Something like keyboard() in Matlab. I know you can do it using
> the debugger, but this still requires a lot of typing: import pdb,
> pdb.run('adsdas') , b , c , ...
>
> I would just like to put 'keyboard()' somewhere in my script, be able
> to examine and change the values of some variables, perhaps call some
> functions, and continue.
I suppose you could use a loop with calls to raw_input() and
exec(), like:
...stuff...
while 1:
cmd = raw_input("cmd: ")
if not cmd:
break
exec(cmd)
...more stuff...
which results in something like
>>> def func():
... print "Hi!"
...
>>> var = 1
>>> while 1:
... cmd = raw_input("cmd: ")
... if not cmd:
... break
... exec(cmd)
...
cmd: func()
Hi!
cmd: var = 2
cmd:
>>> var
2
This only works with one-liners though.
HTH,
Kalle
--
Email: kalle at gnupung.net | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
Not signed due to logistical difficulties (I'm not at home).
If you doubt the authenticity of this message, please tell me.
More information about the Python-list
mailing list