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


Python collections.MappingView方法代碼示例

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


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

示例1: test_abc_registry

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import MappingView [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: is_sequence

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import MappingView [as 別名]
def is_sequence(x) -> bool:
    if isinstance(x, str):
        return False
    return isinstance(x, (collections.Sequence, collections.MappingView)) 
開發者ID:dpressel,項目名稱:mead-baseline,代碼行數:6,代碼來源:utils.py

示例3: is_lazy_iterable

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import MappingView [as 別名]
def is_lazy_iterable(obj):
    """
    Returns whether *obj* is iterable lazily, such as generators, range objects, maps, etc.
    """
    iter_types = (
        types.GeneratorType, collections.MappingView, six.moves.range, six.moves.map, enumerate,
    )
    return isinstance(obj, iter_types) 
開發者ID:riga,項目名稱:law,代碼行數:10,代碼來源:util.py

示例4: sanitize_sequence

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import MappingView [as 別名]
def sanitize_sequence(data):
    """Converts dictview object to list"""
    return list(data) if isinstance(data, collections.MappingView) else data 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:5,代碼來源:__init__.py

示例5: _sequence_like

# 需要導入模塊: import collections [as 別名]
# 或者: from collections import MappingView [as 別名]
def _sequence_like(instance, args):
  """Converts the sequence `args` to the same type as `instance`.

  Args:
    instance: an instance of `tuple`, `list`, `namedtuple`, `dict`, or
        `collections.OrderedDict`.
    args: elements to be converted to the `instance` type.

  Returns:
    `args` with the type of `instance`.
  """
  if isinstance(instance, (dict, collections.Mapping)):
    # Pack dictionaries in a deterministic order by sorting the keys.
    # Notice this means that we ignore the original order of `OrderedDict`
    # instances. This is intentional, to avoid potential bugs caused by mixing
    # ordered and plain dicts (e.g., flattening a dict but using a
    # corresponding `OrderedDict` to pack it back).
    result = dict(zip(_sorted(instance), args))
    keys_and_values = ((key, result[key]) for key in instance)
    if isinstance(instance, collections.defaultdict):
      # `defaultdict` requires a default factory as the first argument.
      return type(instance)(instance.default_factory, keys_and_values)
    elif six.PY3 and isinstance(instance, types.MappingProxyType):
      # MappingProxyType requires a dict to proxy to.
      return type(instance)(dict(keys_and_values))
    else:
      return type(instance)(keys_and_values)
  elif isinstance(instance, collections.MappingView):
    # We can't directly construct mapping views, so we create a list instead
    return list(args)
  elif _is_namedtuple(instance) or _is_attrs(instance):
    if isinstance(instance, ObjectProxy):
      instance_type = type(instance.__wrapped__)
    else:
      instance_type = type(instance)
    return instance_type(*args)
  elif isinstance(instance, ObjectProxy):
    # For object proxies, first create the underlying type and then re-wrap it
    # in the proxy type.
    return type(instance)(_sequence_like(instance.__wrapped__, args))
  else:
    # Not a namedtuple
    return type(instance)(args) 
開發者ID:deepmind,項目名稱:tree,代碼行數:45,代碼來源:__init__.py


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