From b5fb29a11e8cbdff20ec1d0a7a940ed065055c08 Mon Sep 17 00:00:00 2001 From: noah Date: Tue, 13 Aug 2002 12:11:39 +0000 Subject: Initial revision git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@3 656d521f-e311-0410-88e0-e7920216d269 --- pexpect/examples/python.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 pexpect/examples/python.py (limited to 'pexpect/examples/python.py') diff --git a/pexpect/examples/python.py b/pexpect/examples/python.py new file mode 100755 index 0000000..9ba0d61 --- /dev/null +++ b/pexpect/examples/python.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +'''This starts the python interpreter; captures the startup message; then gives the user interactive control over the session. +Why? +''' + +# Don't do this unless you like being John Malkovich +# c = pexpect.spawn ('/usr/bin/env python ./python.py') + +import pexpect +c = pexpect.spawn ('/usr/bin/env python') +c.expect ('>>>') +print 'And now for something completely different...' +f = lambda s:s and f(s[1:])+s[0] # Makes a function to reverse a string. +print f(c.before) +print 'Yes, it\'s python, but it\'s backwards.' +print +print 'Escape character is \'^]\'.' +print c.matched, +c.interact() +c.kill(1) +print 'isAlive:', c.isAlive() + -- cgit v1.2.1