Parsing Complex INI Files with Python ConfigParser - Handling Sections with Duplicates
I'm working on a project and hit a roadblock. I'm trying to parse a configuration file in INI format using Python's `configparser` module. The file can contain multiple sections with the same name, and I need to handle this gracefully. The INI file looks like this: ``` [Database] user = admin password = secret [Database] user = guest password = guestpass [Server] port = 8080 ``` When I attempt to read the file using the following code: ```python import configparser config = configparser.ConfigParser(allow_no_value=True) config.read('config.ini') # Attempting to retrieve database users for section in config.sections(): if section == 'Database': for key in config[section]: print(f'{key}: {config[section][key]}') ``` I only get the values from the last `Database` section, which leads to the output: ``` user: guest password: guestpass ``` Is there a way to configure `configparser` or another approach I can use to collect all entries from duplicate sections? I've looked into `RawConfigParser`, but that doesn't seem to solve my scenario either. I want to ensure that I can access all user credentials listed under the `Database` section, not just the last one. Any help with this would be greatly appreciated! This is part of a larger web app I'm building. How would you solve this?