本文整理汇总了Python中UserDict.DictMixin.items方法的典型用法代码示例。如果您正苦于以下问题:Python DictMixin.items方法的具体用法?Python DictMixin.items怎么用?Python DictMixin.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDict.DictMixin
的用法示例。
在下文中一共展示了DictMixin.items方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import items [as 别名]
def write(self, f):
""" Write namespace as INI file.
:param f: File object or path to file.
"""
if isinstance(f, str):
f = io.open(f, 'w', encoding='utf-8')
if not hasattr(f, 'read'):
raise AttributeError("Wrong type of file: {0}".format(type(f)))
NS_LOGGER.info('Write to `{0}`'.format(f.name))
for section in self.sections.keys():
f.write('[{0}]\n'.format(section))
for k, v in self[section].items():
f.write('{0:15}= {1}\n'.format(k, v))
f.write('\n')
f.close()
示例2: __reduce__
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import items [as 别名]
def __reduce__(self):
items = [[k, self[k]] for k in self]
tmp = self.__map, self.__end
del self.__map, self.__end
inst_dict = vars(self).copy()
self.__map, self.__end = tmp
if inst_dict:
return (self.__class__, (items,), inst_dict)
return self.__class__, (items,)
示例3: __repr__
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import items [as 别名]
def __repr__(self):
if not self:
return '%s()' % (self.__class__.__name__,)
return '%s(%r)' % (self.__class__.__name__, self.items())
示例4: __eq__
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import items [as 别名]
def __eq__(self, other):
if isinstance(other, OrderedDict):
return len(self)==len(other) and self.items() == other.items()
return dict.__eq__(self, other)
示例5: __eq__
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import items [as 别名]
def __eq__(self, other):
if isinstance(other, OrderedDict):
if len(self) != len(other):
return False
for p, q in zip(self.items(), other.items()):
if p != q:
return False
return True
return dict.__eq__(self, other)
示例6: iteritems
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import items [as 别名]
def iteritems(self, raw=False):
""" Iterate self items. """
for key in self:
yield key, self.__getitem__(key, raw=raw)
示例7: __init__
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import items [as 别名]
def __init__(self, **default_items):
self.sections = OrderedDict()
for k, v in default_items.items():
self[self.default_section][k] = v
示例8: parse
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import items [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()
示例9: __eq__
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import items [as 别名]
def __eq__(self, other):
if isinstance(other, OrderedDict):
return len(self)==len(other) and \
all(p==q for p, q in zip(self.items(), other.items()))
return dict.__eq__(self, other)