From 1cb3226c9d2e57b8ec280433c2ad7c990d63bae0 Mon Sep 17 00:00:00 2001 From: Steven Myint Date: Fri, 4 Oct 2013 08:14:19 -0700 Subject: Modernize --- examples/python.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'examples/python.py') 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()) -- cgit v1.2.1