我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用builtins.eval()。
def eval(self, source, globals=None, locals=None, eval_function=None): """ Similar to the built-in function eval() for transpyled code. The additional eval_function() argument allows to define a function to replace Python's builtin compile(). Args: source (str or code): Code to be executed. globals, locals: A globals/locals dictionary eval_function (callable): A possible replacement for Python's built-in eval(). """ eval_function = eval_function or _eval code = self.transpile(source) if isinstance(source, str) else source globals = {} if globals is None else globals globals.update(self.namespace) args = (globals,) if locals is None else (globals, locals) return eval_function(code, *args)
def compile(source, filename, mode, flags=0, dont_inherit=False, compile_function=None): """ Similar to the built-in function compile() for Pytuguês code. The additional compile_function() argument allows to define a function to replace Python's builtin compile(). Args: source (str or code): Code to be executed. filename: File name associated with code. Use '<input>' for strings. mode: One of 'exec' or 'eval'. The second allows only simple statements that generate a value and is used by the eval() function. forbidden (bool): If true, initialize the forbidden lib functionality to enable i18n for Python builtins in C-level. compile_function (callable): A possible replacement for Python's built-in compile(). """ return pytuga_transpyler.compile(**_locals())
def eval(source, globals=None, locals=None, forbidden=False, builtins=False, eval_function=None): """ Similar to the built-in function val() for Pytuguês code. The additional eval_function() argument allows to define a function to replace Python's builtin compile(). Args: source (str or code): Code to be executed. globals, locals: A globals/locals dictionary builtins (bool): If given, update builtins with functions in tugalib. forbidden (bool): If true, initialize the forbidden lib functionality to enable i18n for Python builtins in C-level. eval_function (callable): A possible replacement for Python's built-in eval(). """ return pytuga_transpyler.eval(**_locals())
def eval(expression, _dict={}, **kw): """ Evaluates an image expression. :param expression: A string containing a Python-style expression. :param options: Values to add to the evaluation context. You can either use a dictionary, or one or more keyword arguments. :return: The evaluated expression. This is usually an image object, but can also be an integer, a floating point value, or a pixel tuple, depending on the expression. """ # build execution namespace args = ops.copy() args.update(_dict) args.update(kw) for k, v in list(args.items()): if hasattr(v, "im"): args[k] = _Operand(v) out = builtins.eval(expression, args) try: return out.im except AttributeError: return out
def compile(self, source, filename, mode, flags=0, dont_inherit=False, compile_function=None): """ Similar to the built-in function compile() for Transpyled code. The additional compile_function() argument allows to define a function to replace Python's builtin compile(). Args: source (str or code): Code to be executed. filename: File name associated with code. Use '<input>' for strings. mode: One of 'exec' or 'eval'. The second allows only simple statements that generate a value and is used by the eval() function. forbidden (bool): If true, initialize the forbidden lib functionality to enable i18n for Python builtins in C-level. compile_function (callable): A possible replacement for Python's built-in compile(). """ compile_function = compile_function or _compile source = self.transpile(source) return compile_function(source, filename, mode, flags, dont_inherit)
def eval(expression, _dict={}, **kw): """ Evaluates an image expression. :param expression: A string containing a Python-style expression. :param options: Values to add to the evaluation context. You can either use a dictionary, or one or more keyword arguments. :return: The evaluated expression. This is usually an image object, but can also be an integer, a floating point value, or a pixel tuple, depending on the expression. """ # build execution namespace args = ops.copy() args.update(_dict) args.update(kw) for k, v in list(args.items()): if hasattr(v, "im"): args[k] = _Operand(v) out = builtins.eval(expression, args) try: return out.im except AttributeError: return out # End of file