def safeeval(expr, globals=None, locals=None):
 safe_globals = {'False': False, 'None': None, 'True': True, '__builtin__': None, '__builtins__': None, 'set': set}
 if PY2:
  safe_globals['xrange'] = xrange
 else:
  safe_globals['range'] = range
 def open(*args, **kwargs):
  raise NameError("name 'open' is not defined")
 safe_globals['open'] = open
 if globals:
  safe_globals.update(globals)
 return eval(expr, safe_globals, locals)

def safeeval ( expr , globals = None , locals = None ) : safe_globals = { 'False' : False , 'None' : None , 'True' : True , '__builtin__' : None , '__builtins__' : None , 'set' : set } if PY2 : safe_globals [ 'xrange' ] = xrange else : safe_globals [ 'range' ] = range def open ( * args , ** kwargs ) : raise NameError ( "name 'open' is not defined" ) safe_globals [ 'open' ] = open if globals : safe_globals . update ( globals ) return eval ( expr , safe_globals , locals )
like eval .