Add readline capability to existing interactive program

Jacob Rael jacob.rael at gmail.com
Wed Mar 14 17:05:35 EDT 2007


Hello,

I use an interactive simulator/data plotter called ocean. I get really
frustrated using it because it does not have basic readline
capabilities like ctrl-a for beginning of line and ctrl-k to kill the
rest of the line.

I was thinking this might be easy to add with Python. Do something
like start python and then kick off the ocean job and then use
something like pexpect to interact with it. I think this would work
but there may be an even easier way to do it, maybe directly with
popen2.

A quick google search lead me to:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/108287

and shows code:

import os
f=os.popen('gnuplot', 'w')
print >>f, "set yrange[-300:+300]"
for n in range(300):
	print >>f, "plot %i*cos(x)+%i*log(x+10)" % (n,150-n)
f.flush()


this kind of works but not quite. Windows don't pop open and results
of calculations (3+3) don't echo back.

Before I started coding, I thought I would ask if a module or examples
already exits that do what I want.

jr




More information about the Python-list mailing list