Skip to content

Instantly share code, notes, and snippets.

@agausmann
Last active August 29, 2015 14:24
Show Gist options
  • Save agausmann/b236e9a1c07b2cb1e035 to your computer and use it in GitHub Desktop.
Save agausmann/b236e9a1c07b2cb1e035 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import keyword
def eval_cmd(expr):
try:
for kw in keyword.kwlist:
if kw in expr:
return None
for word in dir():
if word in expr:
return None
return eval(expr)
except Exception as e:
return str(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment