If you just want to merge the identical named sections (the last one winnings), just pass the strict=False parameter to the constructor (added in Python 3.2). You effectively get the behavior of dict.update() as duplicate sections merge.
Config = configparser.ConfigParser(strict=False)
However, it is clear from the OP sample data that identically named partitions must be stored separately to avoid data loss. ConfigParser stores sections that it reads in the dictionary, so it cannot process multiple sections with the same name. Fortunately, the constructor accepts the dict_type argument, which allows you to specify another dictionary-like object. You can use this to support equally named sections. Here's a tough decision that manages section names by adding a unique number whenever the section name has been noticed before.
from collections import OrderedDict class multidict(OrderedDict): _unique = 0
With a little work, you should be able to create a cleaner solution.
alexis
source share