本文整理汇总了Python中UserDict.DictMixin.update方法的典型用法代码示例。如果您正苦于以下问题:Python DictMixin.update方法的具体用法?Python DictMixin.update怎么用?Python DictMixin.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDict.DictMixin
的用法示例。
在下文中一共展示了DictMixin.update方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import update [as 别名]
def read(self, *files, **params):
""" Read and parse INI files.
:param *files: Files for reading
:param **params: Params for parsing
Set `update=False` for prevent values redefinition.
"""
for f in files:
try:
with io.open(f, encoding='utf-8') as ff:
NS_LOGGER.info('Read from `{0}`'.format(ff.name))
self.parse(ff.read(), **params)
except (IOError, TypeError, SyntaxError, io.UnsupportedOperation):
if not self.silent_read:
NS_LOGGER.error('Reading error `{0}`'.format(ff.name))
raise
示例2: __init__
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin 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)
示例3: __init__
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import update [as 别名]
def __init__(self, *args, **kwds):
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
try:
self.__end
except AttributeError:
self.clear()
self.update(*args, **kwds)
示例4: __init__
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import update [as 别名]
def __init__(self, *args, **kwargs):
self.clear()
self.update(*args, **kwargs)
示例5: parse
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import update [as 别名]
def parse(self, source, update=True, **params):
""" Parse INI source as string.
:param source: Source of INI
:param update: Replace already defined items
"""
scanner = INIScanner(source)
scanner.scan()
section = self.default_section
name = None
for token in scanner.tokens:
if token[0] == 'KEY_VALUE':
name, value = re.split('[=:]', token[1], 1)
name, value = name.strip(), value.strip()
if not update and name in self[section]:
continue
self[section][name] = value
elif token[0] == 'SECTION':
section = token[1].strip('[]')
elif token[0] == 'CONTINUATION':
if not name:
raise SyntaxError(
"SyntaxError[@char {0}: {1}]".format(
token[2], "Bad continuation."))
self[section][name] += '\n' + token[1].strip()
示例6: __init__
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import update [as 别名]
def __init__(self, *args, **kwds):
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
try:
self.__end
except AttributeError:
self.clear()
self.update(*args, **kwds)
示例7: update
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import update [as 别名]
def update(self, iterable=None, **kwds):
'''Like dict.update() but add counts instead of replacing them.
Source can be an iterable, a dictionary, or another Counter
instance.
>>> c = Counter('which')
>>> c.update('witch') # add elements from another iterable
>>> d = Counter('watch')
>>> c.update(d) # add elements from another counter
>>> c['h'] # four 'h' in which, witch, and watch
4
'''
if iterable is not None:
if hasattr(iterable, 'iteritems'):
if self:
self_get = self.get
for elem, count in iterable.iteritems():
self[elem] = self_get(elem, 0) + count
else:
# fast path when counter is empty
dict.update(self, iterable)
else:
self_get = self.get
for elem in iterable:
self[elem] = self_get(elem, 0) + 1
if kwds:
self.update(kwds)