Created
February 15, 2013 21:56
-
-
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.
This file contains hidden or 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
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