summaryrefslogtreecommitdiff
path: root/examples/python.py
diff options
context:
space:
mode:
authorSteven Myint <git@stevenmyint.com>2013-10-04 08:14:19 -0700
committerSteven Myint <git@stevenmyint.com>2013-10-04 08:14:19 -0700
commit1cb3226c9d2e57b8ec280433c2ad7c990d63bae0 (patch)
tree87a6f6019ac0d9ee81b3db2b93ac704be458a75c /examples/python.py
parentdd0479cb32e55e882a8d1391af2d5b37f25e2db7 (diff)
downloadpexpect-git-1cb3226c9d2e57b8ec280433c2ad7c990d63bae0.tar.gz
Modernize
Diffstat (limited to 'examples/python.py')
-rwxr-xr-xexamples/python.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/examples/python.py b/examples/python.py
index c095bec..6fa6ddf 100755
--- a/examples/python.py
+++ b/examples/python.py
@@ -22,20 +22,23 @@ PEXPECT LICENSE
'''
+from __future__ import print_function
+
+from __future__ import absolute_import
+
# 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.after,
+c = pexpect.spawnu('/usr/bin/env python')
+c.expect('>>>')
+print('And now for something completely different...')
+print(''.join(reversed((c.before))))
+print('Yes, it\'s python, but it\'s backwards.')
+print()
+print('Escape character is \'^]\'.')
+print(c.after, end=' ')
c.interact()
c.kill(1)
-print 'is alive:', c.isalive()
+print('is alive:', c.isalive())