当前位置: 首页>>代码示例>>Python>>正文


Python builtins.getattr方法代码示例

本文整理汇总了Python中builtins.getattr方法的典型用法代码示例。如果您正苦于以下问题:Python builtins.getattr方法的具体用法?Python builtins.getattr怎么用?Python builtins.getattr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在builtins的用法示例。


在下文中一共展示了builtins.getattr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __enter__

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import getattr [as 别名]
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 
开发者ID:spotify,项目名称:pythonflow,代码行数:7,代码来源:core.py

示例2: evaluate_operation

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import getattr [as 别名]
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) 
开发者ID:spotify,项目名称:pythonflow,代码行数:36,代码来源:core.py

示例3: getattr

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import getattr [as 别名]
def getattr(obj, attr, *args):
    '''Replacement for the built-in
    :func:`getattr() <python:getattr>` function.'''
    return builtins.getattr(obj, attr, *args) 
开发者ID:eth-cscs,项目名称:reframe,代码行数:6,代码来源:sanity.py

示例4: getattr_or

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import getattr [as 别名]
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) 
开发者ID:fabiommendes,项目名称:sidekick,代码行数:8,代码来源:builtins.py


注:本文中的builtins.getattr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。