Skip to content

Instantly share code, notes, and snippets.

@obfusk
Created May 27, 2016 23:50
Show Gist options
  • Save obfusk/7d1cedf698d217d3cc4b90028951a594 to your computer and use it in GitHub Desktop.
Save obfusk/7d1cedf698d217d3cc4b90028951a594 to your computer and use it in GitHub Desktop.
python repl example
#!/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