Skip to content

Instantly share code, notes, and snippets.

@vikramdurai
Created April 16, 2017 07:18
Show Gist options
  • Save vikramdurai/82a2aaec2866b9ca353eddc6308a2374 to your computer and use it in GitHub Desktop.
Save vikramdurai/82a2aaec2866b9ca353eddc6308a2374 to your computer and use it in GitHub Desktop.
A command-line interpreter for Python
"""A basic interpreter for Python, using the eval() function."""
# print startup info
print("Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32")
print("Type \"copyright\", \"credits\" or \"license()\" for more information.")
while True:
code = input(">>> ")
# try to run the code entered
try:
eval(code)
# if not, catch the error
# and throw it to the screen
# TODO: Throw tracebacks to the screen too
except Exception as err:
print(str(err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment