Created
May 27, 2016 23:50
-
-
Save obfusk/7d1cedf698d217d3cc4b90028951a594 to your computer and use it in GitHub Desktop.
python repl example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from __future__ import print_function | |
import sys | |
if sys.version_info.major == 2: | |
def prompt(s = ">>> "): return raw_input(s) | |
else: | |
def prompt(s = ">>> "): return input(s) | |
def f(line): return "".join(reversed(line)) | |
if sys.stdin.isatty(): | |
try: | |
import readline | |
except ImportError: | |
pass | |
while True: | |
try: | |
line = prompt() | |
except EOFError: | |
print(); break | |
if line: print(f(line)) | |
else: | |
for line in ( l.rstrip("\n") for l in sys.stdin ): | |
print(f(line)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment