summaryrefslogtreecommitdiff
path: root/pexpect/examples/python.py
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2002-08-13 12:11:39 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2002-08-13 12:11:39 +0000
commitb5fb29a11e8cbdff20ec1d0a7a940ed065055c08 (patch)
tree7d0d9050cce04f2efa9b57be8b7e6d1b369addba /pexpect/examples/python.py
parentf5a4fdf25a59020794583dc401e5c56f0543648e (diff)
downloadpexpect-b5fb29a11e8cbdff20ec1d0a7a940ed065055c08.tar.gz
Initial revision
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@3 656d521f-e311-0410-88e0-e7920216d269
Diffstat (limited to 'pexpect/examples/python.py')
-rwxr-xr-xpexpect/examples/python.py22
1 files changed, 22 insertions, 0 deletions
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()
+