File: python.py

package info (click to toggle)
pexpect 2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 560 kB
  • sloc: python: 4,337; makefile: 2
file content (22 lines) | stat: -rwxr-xr-x 660 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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()