本文整理汇总了Python中collections.MutableMapping.update方法的典型用法代码示例。如果您正苦于以下问题:Python MutableMapping.update方法的具体用法?Python MutableMapping.update怎么用?Python MutableMapping.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collections.MutableMapping
的用法示例。
在下文中一共展示了MutableMapping.update方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from collections import MutableMapping [as 别名]
# 或者: from collections.MutableMapping import update [as 别名]
def update(self, *args, **kwargs):
if len(args) > 1:
raise TypeError("update() takes at most 1 positional "
"arguments ({} given)".format(len(args)))
if len(args) >= 1:
other = args[0]
if isinstance(other, KeyedList):
# Merge
for key, value in other.all_items():
self[key] = value
else:
MutableMapping.update(self, other)
for key, value in kwargs.items():
if isinstance(value, KeyedList):
try:
subkl = self[key]
except KeyError:
subkl = KeyedList()
self[key] = subkl
else:
if not isinstance(subkl, KeyedList):
raise KeyError('target key "%s" is a value, cannot '
'update value against another keyed list' %
(key,))
subkl.update(value)
else:
self[key] = value
示例2: update
# 需要导入模块: from collections import MutableMapping [as 别名]
# 或者: from collections.MutableMapping import update [as 别名]
def update(*args, **kwds):
self = args[0]
with FastInserter(self.cursor):
MutableMapping.update(*args, **kwds)
# make table and index stored contiguously
self.cursor.execute("VACUUM")
示例3: update
# 需要导入模块: from collections import MutableMapping [as 别名]
# 或者: from collections.MutableMapping import update [as 别名]
def update(self, *args, **kw):
if args:
lst = args[0]
if len(lst) != len(dict(lst)):
# this does not catch the cases where we overwrite existing
# keys, but those would produce too many warning
msg = ("Behavior of MultiDict.update() has changed "
"and overwrites duplicate keys. Consider using .extend()"
)
warnings.warn(msg, UserWarning, stacklevel=2)
MutableMapping.update(self, *args, **kw)
示例4: __init__
# 需要导入模块: from collections import MutableMapping [as 别名]
# 或者: from collections.MutableMapping import update [as 别名]
def __init__(*args, **kwargs):
if not args:
raise TypeError("OrderedDict.__init__() needs an instance as the first argument")
self = args[0]
args = args[1:]
if len(args) > 1:
raise TypeError("OrderedDict() takes at most 1 positional argument, got %d" % len(args))
dict.__init__(self)
if not self:
self._keys = []
MutableMapping.update(self, *args, **kwargs)