[IPython-user] Recording sessions

Ken Schutte kschutte at csail.mit.edu
Sat May 27 08:19:31 CDT 2006


Fernando Perez wrote:
> No, something like that doesn't really currently exist.  Short of
> building a true 'notebook' interface (for which we do have a proof of
> concept prototype, but nothing production-ready), you might be able to
> hack together an expect-based system which feeds a file, one line at a
> time, to a running ipython.

expect was another tool I didn't know about... I found the Pexpect 
python module (pexpect.sourceforge.net) and that made it easy to throw 
something together that does the trick,

import pexpect, sys
c = pexpect.spawn('/usr/bin/env ipython -colors NoColor')
c.expect('In \[\d+\]: ')
sys.stdout.write(c.after)
f=open('my_cmds.py')
for cmd in f:
     c.sendline(cmd[0:-1])
     c.expect('In \[\d+\]: ')
     sys.stdout.write(c.before)
     sys.stdout.write(c.after)


Thanks!

Ken




More information about the IPython-user mailing list