using pexpect to control python

Maurice LING mauriceling at
Wed Aug 25 00:45:29 CEST 2004

I suppose I'm actually still toying with the possibilities of what 
pexpect can do with python and the question comes up.

Another thing which I'm thinking previously is how can I embed a python 
interpreter (not compiler) that does line by line interpretation and 
execution, in a python program? I realized that python's language 
services has a compile package that can be invoked to compile python 
source into python bytecodes but that's provided that the codes are in a 
file. Perhaps what I'm interested may be how to embed and use the 
interactive mode of python interpreter in a python program?

> That last is *always* an apt question.
> Don Libes invented Expect.  Expect is a wonderful, wonderful thing;
> at the same time, its purpose is to mollify "programs with crappy
> interfaces" (his words), so it's dispensable and inherently sub-op-
> timal, in a sense I think we can make precise.  The point here is
> that, whenever you're considering controlling a Python-based appli-
> cation PP with Expect (or pexpect or ...), you should first invest
> at least ten seconds analyzing whether you're better off re-doing
> PP's interface.

More information about the Python-list mailing list