當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。