Skip to content

Instantly share code, notes, and snippets.

@bebraw
Created January 10, 2010 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bebraw/273366 to your computer and use it in GitHub Desktop.
Save bebraw/273366 to your computer and use it in GitHub Desktop.
class Python:
priority = 'low'
def matches(self, expression):
return True
def execute(self, expression, variables):
'''
>>> from py.test import raises
>>> python = Python()
>>> python.execute('5+13', {})
18
>>> python.execute('a+7', {'a': 13, })
20
>>> exception = raises(NameError, python.execute, 'foobar', {})
>>> exception.typename
'NameError'
'''
return eval(expression, {}, variables)
if __name__ == "__main__":
import doctest
doctest.testmod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment