进行少量修改后,我就能实现您想要的:
class MultiOrderedDict(OrderedDict): def __setitem__(self, key, value): if isinstance(value, list) and key in self: self[key].extend(value) else: super(MultiOrderedDict, self).__setitem__(key, value) # super().__setitem__(key, value) in Python 3config = ConfigParser.RawConfigParser(dict_type=MultiOrderedDict)config.read(['a.txt'])print config.get("test", "foo")print config.get("test", "xxx")
输出:
['value1', 'value2']['yyy']
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)