parameters: (expression, variable_names)
return_statement: return eval_expression.strip()
docstring: Transform a string expression into one usable by eval.
docstring_summary: Transform a string expression into one usable by eval.
docstring_tokens: Transform a string expression into one usable by eval .
function: def _transform_eval_expression(expression, variable_names):
          """Transform a string expression into one usable by eval."""
          eval_expression = ' %s ' % expression
          for name in variable_names:
              eval_expression = re.sub('([^a-zA-Z0-9_])%s([^a-zA-Z0-9_])' % name,
                                       r"\1var['%s']\2" % name, eval_expression)
          # add "math." to supported mathematical functions
          # Note: abs is a built-in function, it is not math.abs
          for name in [
                  'atan', 'sinh', 'cosh', 'tanh', 'exp', 'sqrt', 'sin', 'cos',
                  'tan'
          ]:
              eval_expression = re.sub('([^a-zA-Z0-9_])%s([^a-zA-Z0-9_])' % name,
                                       r'\1math.%s\2' % name, eval_expression)
          # convert powers to from "^" to "**" format
          eval_expression = re.sub(r'\^', '**', eval_expression)
          return eval_expression.strip()
function_tokens: def _transform_eval_expression ( expression , variable_names ) : eval_expression = ' %s ' % expression for name in variable_names : eval_expression = re . sub ( '([^a-zA-Z0-9_])%s([^a-zA-Z0-9_])' % name , r"\1var['%s']\2" % name , eval_expression ) # add "math." to supported mathematical functions # Note: abs is a built-in function, it is not math.abs for name in [ 'atan' , 'sinh' , 'cosh' , 'tanh' , 'exp' , 'sqrt' , 'sin' , 'cos' , 'tan' ] : eval_expression = re . sub ( '([^a-zA-Z0-9_])%s([^a-zA-Z0-9_])' % name , r'\1math.%s\2' % name , eval_expression ) # convert powers to from "^" to "**" format eval_expression = re . sub ( r'\^' , '**' , eval_expression ) return eval_expression . strip ( )