Skip to content

Instantly share code, notes, and snippets.

@zeha
Created February 15, 2013 21:56
Show Gist options
  • Save zeha/4963871 to your computer and use it in GitHub Desktop.
Save zeha/4963871 to your computer and use it in GitHub Desktop.
minimal interactive python interpreter. useless because you could just call code.InteractiveConsole().interact() instead.
from __future__ import print_function
import traceback
import sys
def run():
print("minirepl on Python", sys.version)
continued = False
line = None
while True:
try:
prefix = ">>>"
if continued:
prefix = "..."
print(prefix, end=" ")
line_ = raw_input()
if line is not None:
line = line + "\n" + line_
else:
line = line_
if line != '':
rv = eval(line)
print(repr(rv))
continued = False
line = None
except EOFError as e:
return 0
except SyntaxError as e:
if 'unexpected EOF' in str(e):
continued = True
else:
continued = False
traceback.print_exc()
except KeyboardInterrupt as e:
print(e)
except Exception as e:
traceback.print_exc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment