1 #!/usr/bin/env python 2 3 """This starts the python interpreter; captures the startup message; then gives 4 the 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 9 import pexpect 10 c = pexpect.spawn ('/usr/bin/env python') 11 c.expect ('>>>') 12 print 'And now for something completely different...' 13 f = lambda s:s and f(s[1:])+s[0] # Makes a function to reverse a string. 14 print f(c.before) 15 print 'Yes, it\'s python, but it\'s backwards.' 16 print 17 print 'Escape character is \'^]\'.' 18 print c.after, 19 c.interact() 20 c.kill(1) 21 print 'is alive:', c.isalive() 22 23