X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Flink%2Fpexpect%2Fexamples%2Fpython.py;fp=src%2Flink%2Fpexpect%2Fexamples%2Fpython.py;h=d8c986652e6d7a343a5eb62ce6d618bd871b7916;hb=cd42b53c196672694396e695ae17fd94ba7d58b4;hp=0000000000000000000000000000000000000000;hpb=e9a8105a8f22404f4ac550d79954eaa6b7f5d8ff;p=progcomp10.git diff --git a/src/link/pexpect/examples/python.py b/src/link/pexpect/examples/python.py new file mode 100755 index 0000000..d8c9866 --- /dev/null +++ b/src/link/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? For fun... """ + +# 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.interact() +c.kill(1) +print 'is alive:', c.isalive() +