當前位置: 首頁>>代碼示例>>Python>>正文


Python collections.ItemsView方法代碼示例

本文整理匯總了Python中collections.ItemsView方法的典型用法代碼示例。如果您正苦於以下問題:Python collections.ItemsView方法的具體用法?Python collections.ItemsView怎麽用?Python collections.ItemsView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在collections的用法示例。


在下文中一共展示了collections.ItemsView方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_abc_registry

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import ItemsView [as 別名]
def test_abc_registry(self):
        d = dict(a=1)

        self.assertIsInstance(d.viewkeys(), collections.KeysView)
        self.assertIsInstance(d.viewkeys(), collections.MappingView)
        self.assertIsInstance(d.viewkeys(), collections.Set)
        self.assertIsInstance(d.viewkeys(), collections.Sized)
        self.assertIsInstance(d.viewkeys(), collections.Iterable)
        self.assertIsInstance(d.viewkeys(), collections.Container)

        self.assertIsInstance(d.viewvalues(), collections.ValuesView)
        self.assertIsInstance(d.viewvalues(), collections.MappingView)
        self.assertIsInstance(d.viewvalues(), collections.Sized)

        self.assertIsInstance(d.viewitems(), collections.ItemsView)
        self.assertIsInstance(d.viewitems(), collections.MappingView)
        self.assertIsInstance(d.viewitems(), collections.Set)
        self.assertIsInstance(d.viewitems(), collections.Sized)
        self.assertIsInstance(d.viewitems(), collections.Iterable)
        self.assertIsInstance(d.viewitems(), collections.Container) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_dictviews.py

示例2: items

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import ItemsView [as 別名]
def items(self):
        return ItemsView(self) 
開發者ID:PacktPublishing,項目名稱:Python-Journey-from-Novice-to-Expert,代碼行數:4,代碼來源:6_16_dictsorted.py

示例3: viewitems

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import ItemsView [as 別名]
def viewitems(self):
        "Return set-like object with view of mapping items."
        return ItemsView(self) 
開發者ID:eirannejad,項目名稱:pyRevit,代碼行數:5,代碼來源:ordereddict.py

示例4: default_enter

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import ItemsView [as 別名]
def default_enter(path, key, value):
    # print('enter(%r, %r)' % (key, value))
    if isinstance(value, basestring):
        return value, False
    elif isinstance(value, Mapping):
        return value.__class__(), ItemsView(value)
    elif isinstance(value, Sequence):
        return value.__class__(), enumerate(value)
    elif isinstance(value, Set):
        return value.__class__(), enumerate(value)
    else:
        # files, strings, other iterables, and scalars are not
        # traversed
        return value, False 
開發者ID:HunterMcGushion,項目名稱:hyperparameter_hunter,代碼行數:16,代碼來源:boltons_utils.py

示例5: viewitems

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import ItemsView [as 別名]
def viewitems(self):
    return collections.ItemsView(self) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:4,代碼來源:request_environment.py

示例6: items

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import ItemsView [as 別名]
def items(self):
        """D.items() => a set-like object providing a view on D's items"""
        return stdlib_collections.ItemsView(self) 
開發者ID:compas-dev,項目名稱:compas,代碼行數:5,代碼來源:_mutablemapping.py

示例7: for_various_result_types_of__filter_by_which

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import ItemsView [as 別名]
def for_various_result_types_of__filter_by_which(test_meth):

    # Taking into consideration that the data specification's
    # overridable method `filter_by_which()` is required to return a
    # container that is either a *dict items view* or a *set-like*
    # object, we want to ensure that the methods which call
    # `filter_by_which()` handle the call results properly for various
    # types of these results (i.e., regardless of whether the result is
    # a *dict items view* or a *set-like* object; regardless of whether
    # the object is an instance of a builtin type or of a custom one;
    # and regardless of whether the object is mutable or immutable...).
    #
    # By wrapping with this decorator a test of a data specification's
    # method which uses `filter_by_which()` call results *and* by
    # decorating the test case class that contains such a test with
    # `@unittest_expander.expand` -- we ensure that the method will be
    # tested for various kinds of types of `filter_by_which()` call
    # results.

    @foreach([
        None,
        lambda iterable: dict(iterable).viewitems(),
        lambda iterable: collections.ItemsView(dict(iterable)),
        frozenset,
        set,
        CustomImmutableSet,
        CustomMutableSet,
    ])
    @functools.wraps(test_meth)
    def decorated_test_meth(self, result_type_adjuster):
        if result_type_adjuster is None:
            test_meth(self)
            return
        called = []
        wrapped = _make_wrapped__filter_by_which(
            result_type_adjuster,
            called,
            orig=self.base_data_spec_class.filter_by_which)
        with patch.object(self.base_data_spec_class, 'filter_by_which', wrapped):
            assert not called, 'bug in the test'
            test_meth(self)
            assert called, 'bug in the test'

    def _make_wrapped__filter_by_which(result_type_adjuster, called, orig):
        @staticmethod
        def wrapped(*args, **kwargs):
            called.append(None)
            orig_result = orig(*args, **kwargs)
            return result_type_adjuster(orig_result)
        return wrapped

    return decorated_test_meth



#
# Mix-ins for test case classes
# 
開發者ID:CERT-Polska,項目名稱:n6,代碼行數:60,代碼來源:test_data_spec.py


注:本文中的collections.ItemsView方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。