0

I want to use maxima from python using pexpect, whenever maxima starts it will print a bunch of stuff of this form:

$ maxima
Maxima 5.27.0 http://maxima.sourceforge.net
using Lisp SBCL 1.0.57-1.fc17
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1)

i would like to start up pexpect like so:

import pexpect 
cmd = 'maxima'
child = pexpect.spawn(cmd)
child.expect (' match all that stuff up to and including (%i1)')
child.sendline ('integrate(sin(x),x)')
chil.expect( match (%i2) i think ; see below sample session  ) 
print child.before 

how do i match the starting banner up to the prompt (%i1)? and so on, also maxima increments the (%i1)'s by one as the session goes along,

(%i1) integrate(sin(x),x);
(%o1)                              - cos(x)
(%i2) integrate(log(x),x);
(%o2)                            x log(x) - x
(%i3)

so the next expect would be:

child.expect ('match (%i2)')
child.sendline ('integrate(log(x),x)')
child.expect( match (%i3) ) 
print child.before 

how do i match the (incrementing) integers? Basically i need to match the (%i#)'s while printing the (%o#)'s.

Mark Chackerian
  • 21,866
  • 6
  • 108
  • 99
mike
  • 897
  • 2
  • 10
  • 29

1 Answers1

1

This regex matches it: \(%i\d\). If you needed to match the (%o#)s just replace i with o in the needle.

Brigand
  • 84,529
  • 20
  • 165
  • 173