0

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 を起動したいと思います。

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 

開始バナーをプロンプト (%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#) を一致させる必要があります。

4

1 に答える 1

1

この正規表現はそれに一致します: \(%i\d\). sを一致させる必要がある場合は、針をに(%o#)置き換えます。io

于 2012-12-15T11:27:55.027 に答える