Python builtins.getattr() Examples
The following are 4
code examples of builtins.getattr().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
builtins
, or try the search function
.
Example #1
Source File: core.py From pythonflow with Apache License 2.0 | 5 votes |
def __enter__(self): assert getattr(self._globals, 'default_graph', None) is None, \ "cannot have more than one default graph" Graph._globals.default_graph = self return self
Example #2
Source File: core.py From pythonflow with Apache License 2.0 | 5 votes |
def evaluate_operation(cls, operation, context, **kwargs): """ Evaluate an operation or constant given a context. """ try: if isinstance(operation, Operation): return operation.evaluate(context, **kwargs) partial = functools.partial(cls.evaluate_operation, context=context, **kwargs) if isinstance(operation, tuple): return tuple(partial(element) for element in operation) if isinstance(operation, list): return [partial(element) for element in operation] if isinstance(operation, dict): return {partial(key): partial(value) for key, value in operation.items()} if isinstance(operation, slice): return slice(*[partial(getattr(operation, attr)) for attr in ['start', 'stop', 'step']]) return operation except Exception as ex: # pragma: no cover stack = [] interactive = False for frame in reversed(operation._stack): # pylint: disable=protected-access # Do not capture any internal stack traces if 'pythonflow' in frame.filename: continue # Stop tracing at the last interactive cell if interactive and not frame.filename.startswith('<'): break # pragma: no cover interactive = frame.filename.startswith('<') stack.append(frame) stack = "".join(traceback.format_list(reversed(stack))) message = "Failed to evaluate operation `%s` defined at:\n\n%s" % (operation, stack) raise ex from EvaluationError(message)
Example #3
Source File: sanity.py From reframe with BSD 3-Clause "New" or "Revised" License | 5 votes |
def getattr(obj, attr, *args): '''Replacement for the built-in :func:`getattr() <python:getattr>` function.''' return builtins.getattr(obj, attr, *args)
Example #4
Source File: builtins.py From sidekick with MIT License | 5 votes |
def getattr_or(default, attr, obj): """ Return given attribute of object or the default argument if attr is not given. """ return _builtins.getattr(obj, attr, default)