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


Python abc.KeysView方法代码示例

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


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

示例1: extra_serializer

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import KeysView [as 别名]
def extra_serializer(obj: Any) -> Union[int, str, List[Any], Dict[str, Any]]:
    """JSON serializer for objects not serializable by default json code"""

    if isinstance(obj, datetime.datetime):
        return dtutil.dt2ts(obj)
    if isinstance(obj, bytes):
        return obj.decode('utf-8')
    if isinstance(obj, decimal.Decimal):
        return obj.to_eng_string()
    if isinstance(obj, (set, KeysView)):
        return list(obj)
    if isinstance(obj, Exception):
        stack = traceback.extract_tb(obj.__traceback__)
        return traceback.format_list(stack)
    if hasattr(obj, 'to_dict'):
        return obj.to_dict()
    if hasattr(obj, '__attrs_attrs__'):
        val: Dict[str, Any] = {}
        for a in obj.__attrs_attrs__:
            val[a.name] = getattr(obj, a.name)
        return val
    raise TypeError('Type {t} not serializable - {obj}'.format(t=type(obj), obj=obj)) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:24,代码来源:serialization.py

示例2: test_MutableMapping_subclass

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import KeysView [as 别名]
def test_MutableMapping_subclass(self):
        # Test issue 9214
        mymap = UserDict()
        mymap['red'] = 5
        self.assertIsInstance(mymap.keys(), Set)
        self.assertIsInstance(mymap.keys(), KeysView)
        self.assertIsInstance(mymap.items(), Set)
        self.assertIsInstance(mymap.items(), ItemsView)

        mymap = UserDict()
        mymap['red'] = 5
        z = mymap.keys() | {'orange'}
        self.assertIsInstance(z, set)
        list(z)
        mymap['blue'] = 7               # Shouldn't affect 'z'
        self.assertEqual(sorted(z), ['orange', 'red'])

        mymap = UserDict()
        mymap['red'] = 5
        z = mymap.items() | {('orange', 3)}
        self.assertIsInstance(z, set)
        list(z)
        mymap['blue'] = 7               # Shouldn't affect 'z'
        self.assertEqual(sorted(z), [('orange', 3), ('red', 5)]) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_collections.py

示例3: variables

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import KeysView [as 别名]
def variables(self):
        """The variables of the binary quadratic model."""
        return KeysView(self.linear) 
开发者ID:dwavesystems,项目名称:dimod,代码行数:5,代码来源:bqm.py

示例4: keys

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import KeysView [as 别名]
def keys(self):
        return KeysView(self) 
开发者ID:pikepdf,项目名称:pikepdf,代码行数:4,代码来源:_methods.py

示例5: make_unique_list

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import KeysView [as 别名]
def make_unique_list(key, allow_array=False):
    if isinstance(key, (Index, abc.KeysView)):
        key = list(key)
    is_list = (
        isinstance(key, (list, tuple, np.record))
        if allow_array
        else isinstance(key, (list, tuple, np.ndarray, np.record))
    )
    is_list_of_str = is_list and all(isinstance(item, str) for item in key)
    return key if is_list_of_str else key if is_list and len(key) < 20 else [key] 
开发者ID:theislab,项目名称:scvelo,代码行数:12,代码来源:utils.py

示例6: has_intrinsic_functions

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import KeysView [as 别名]
def has_intrinsic_functions(parameter):
    intrinsic_functions = ["Fn::Sub", "!Sub", "!GetAtt"]
    result = False
    if isinstance(parameter, (list, tuple, dict, KeysView)):
        for item in parameter:
            if item in intrinsic_functions:
                result = True
                break
    return result 
开发者ID:awslabs,项目名称:aws-cfn-template-flip,代码行数:11,代码来源:__init__.py

示例7: keys

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import KeysView [as 别名]
def keys(self) -> KeysView:
        r"""Return all keys of the resources.
        """
        return self.resources.keys() 
开发者ID:asyml,项目名称:forte,代码行数:6,代码来源:resources.py

示例8: keys

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import KeysView [as 别名]
def keys(self):
        "D.keys() -> a set-like object providing a view on D's keys"
        return KeysView(self) 
开发者ID:benbovy,项目名称:xarray-simlab,代码行数:5,代码来源:utils.py

示例9: keys

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import KeysView [as 别名]
def keys(self):
        """D.keys() => a set-like object providing a view on D's keys"""
        return stdlib_collections.KeysView(self) 
开发者ID:compas-dev,项目名称:compas,代码行数:5,代码来源:_mutablemapping.py

示例10: short_repr

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import KeysView [as 别名]
def short_repr(obj, noneAsNA=False):
    '''Return a short representation of obj for clarity.'''
    if obj is None:
        return 'unspecified' if noneAsNA else 'None'
    elif isinstance(obj, str) and len(obj) > 80:
        return '{}...{}'.format(obj[:60].replace('\n', '\\n'),
                                obj[-20:].replace('\n', '\\n'))
    elif isinstance(obj, (str, int, float, bool)):
        return repr(obj)
    elif hasattr(obj, '__short_repr__'):
        return obj.__short_repr__()
    elif isinstance(obj, Sequence):  # should be a list or tuple
        if len(obj) == 0:
            return '[]'
        elif len(obj) == 1:
            return f'{short_repr(obj[0])}'
        elif len(obj) == 2:
            return f'{short_repr(obj[0])}, {short_repr(obj[1])}'
        else:
            return f'{short_repr(obj[0])}, {short_repr(obj[1])}, ... ({len(obj)} items)'
    elif isinstance(obj, dict):
        if not obj:
            return ''
        elif len(obj) == 1:
            first_key = list(obj.keys())[0]
            return f'{short_repr(first_key)!r}:{short_repr(obj[first_key])!r}'
        else:
            first_key = list(obj.keys())[0]
            return f'{short_repr(first_key)}:{short_repr(obj[first_key])}, ... ({len(obj)} items)'
    elif isinstance(obj, KeysView):
        if not obj:
            return ''
        elif len(obj) == 1:
            return short_repr(next(iter(obj)))
        else:
            return f'{short_repr(next(iter(obj)))}, ... ({len(obj)} items)'
    # elif hasattr(obj, 'target_name'):
    #    return obj.target_name()
    else:
        ret = str(obj)
        if len(ret) > 40:
            return f'{repr(obj)[:35]}...'
        else:
            return ret


#
# SoS Workflow dictionary
# 
开发者ID:vatlab,项目名称:sos,代码行数:51,代码来源:utils.py


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