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


Python DictMixin.update方法代码示例

本文整理汇总了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 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:20,代码来源:inirama.py

示例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) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:22,代码来源:python2x.py

示例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) 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:10,代码来源:_ordered_dict.py

示例4: __init__

# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import update [as 别名]
def __init__(self, *args, **kwargs):
            self.clear()
            self.update(*args, **kwargs) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:5,代码来源:inirama.py

示例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() 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:32,代码来源:inirama.py

示例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) 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:10,代码来源:ordereddict.py

示例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) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:30,代码来源:python2x.py


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