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


Python MutableMapping.update方法代码示例

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


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

示例1: extend

# 需要导入模块: from collections import MutableMapping [as 别名]
# 或者: from collections.MutableMapping import update [as 别名]
def extend(self, *args, **kwargs):
        """Generic import function for any type of header-like object.
        Adapted version of MutableMapping.update in order to insert items
        with self.add instead of self.__setitem__
        """
        if len(args) > 1:
            raise TypeError("extend() takes at most 1 positional "
                            "arguments ({} given)".format(len(args)))
        other = args[0] if len(args) >= 1 else ()
        
        if isinstance(other, HTTPHeaderDict):
            for key, val in other.iteritems():
                self.add(key, val)
        elif isinstance(other, Mapping):
            for key in other:
                self.add(key, other[key])
        elif hasattr(other, "keys"):
            for key in other.keys():
                self.add(key, other[key])
        else:
            for key, value in other:
                self.add(key, value)

        for key, value in kwargs.items():
            self.add(key, value) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:27,代码来源:_collections.py

示例2: extend

# 需要导入模块: from collections import MutableMapping [as 别名]
# 或者: from collections.MutableMapping import update [as 别名]
def extend(self, *args, **kwargs):
        """Generic import function for any type of header-like object.
        Adapted version of MutableMapping.update in order to insert items
        with self.add instead of self.__setitem__
        """
        if len(args) > 1:
            raise TypeError("extend() takes at most 1 positional "
                            "arguments ({0} given)".format(len(args)))
        other = args[0] if len(args) >= 1 else ()

        if isinstance(other, HTTPHeaderDict):
            for key, val in other.iteritems():
                self.add(key, val)
        elif isinstance(other, Mapping):
            for key in other:
                self.add(key, other[key])
        elif hasattr(other, "keys"):
            for key in other.keys():
                self.add(key, other[key])
        else:
            for key, value in other:
                self.add(key, value)

        for key, value in kwargs.items():
            self.add(key, value) 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:27,代码来源:_collections.py

示例3: __init__

# 需要导入模块: from collections import MutableMapping [as 别名]
# 或者: from collections.MutableMapping import update [as 别名]
def __init__(*args, **kwds):
        '''Create a new, empty Counter object.  And if given, count elements
        from an input iterable.  Or, initialize the count from another mapping
        of elements to their counts.

        >>> c = Counter()                           # a new, empty counter
        >>> c = Counter('gallahad')                 # a new counter from an iterable
        >>> c = Counter({'a': 4, 'b': 2})           # a new counter from a mapping
        >>> c = Counter(a=4, b=2)                   # a new counter from keyword args

        '''
        if not args:
            raise TypeError("descriptor '__init__' of 'Counter' object "
                            "needs an argument")
        self = args[0]
        args = args[1:]
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))
        super(Counter, self).__init__()
        self.update(*args, **kwds) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:22,代码来源:misc.py

示例4: __init__

# 需要导入模块: from collections import MutableMapping [as 别名]
# 或者: from collections.MutableMapping import update [as 别名]
def __init__(self, iterable=None, **kwds):
            '''Create a new, empty Counter object.

            And if given, count elements from an input iterable.  Or,
            initialize the count from another mapping of elements to
            their counts.

            A new, empty counter:
            >>> c = Counter()

            A new counter from an iterable
            >>> c = Counter('gallahad')

            A new counter from a mapping
            >>> c = Counter({'a': 4, 'b': 2})

            A new counter from keyword args
            >>> c = Counter(a=4, b=2)
            '''
            self.update(iterable, **kwds) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:22,代码来源:python2x.py


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