Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import operator, re
- def _match(pattern, _string):
- return True if re.match(pattern, _string) else False
- numeric_types_operators = { '<' : operator.lt, '<=': operator.le, '==': operator.eq, '!=': operator.ne, '>=': operator.ge,'>' : operator.gt }
- allowed_operators = {
- boolean : {
- '==': operator.eq,
- '!=': operator.ne,
- }, int : numeric_types_operators,
- float : numeric_types_operators,
- string : {
- 'match' : _match
- }
- }
- def evaluate(value, eval_string):
- """ eval string example: operator value_to_compare """
- operation, value_to_compare = eval_string.split(" ")
- return allower_operators[type(value)][operation](value, value_to_compare)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement