如何匹配python pexp中的正则表达式(%i1)

2024-10-04 05:31:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用pexpect使用python中的maxima,每当maxima启动时,它都会打印出以下形式的大量内容:

$ 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)

我希望像这样启动pexpect:

^{pr2}$

如何将起始横幅与提示符(%i1)匹配? 以此类推,随着会话的进行,maxima也会将(%i1)的值增加1

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

所以下一个期望是:

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

如何匹配(递增)整数? 基本上,我需要在打印(%o)时匹配(%i)


Tags: thelogchild内容matchbug形式expect