1#!/usr/bin/env python
2
3"""This starts the python interpreter; captures the startup message; then gives
4the user interactive control over the session. Why? For fun... """
5
6# Don't do this unless you like being John Malkovich
7# c = pexpect.spawn ('/usr/bin/env python ./python.py')
8
9import pexpect
10c = pexpect.spawn ('/usr/bin/env python')
11c.expect ('>>>')
12print 'And now for something completely different...'
13f = lambda s:s and f(s[1:])+s[0] # Makes a function to reverse a string.
14print f(c.before)
15print 'Yes, it\'s python, but it\'s backwards.'
16print
17print 'Escape character is \'^]\'.'
18print c.after,
19c.interact()
20c.kill(1)
21print 'is alive:', c.isalive()
22
23