Pexpect is a pure Python module that makes Python a better tool for controlling and automating other programs. Pexpect is similar to the Don Libes Expect system, but Pexpect as a different interface that is easier to understand.
It runs programs and watches output. When output matches a given pattern Pexpect can respond as if a human were typing responses.
Read the full thing at http://www.topdog.za.net/2012/04/25/python-modules-you-should-know:-pexpect/