I would like to read a configuration file with the python ConfigParser module:
[asection]
option_a = first_value
option_a = second_value
And I want to be able to get the list of values specified for option 'option_a'. I tried the obvious following:
test = """[asection]
option_a = first_value
option_a = second_value
"""
import ConfigParser, StringIO
f = StringIO.StringIO(test)
parser = ConfigParser.ConfigParser()
parser.readfp(f)
print parser.items()
Which outputs:
[('option_a', 'second_value')]
While I was hoping for:
[('option_a', 'first_value'), ('option_a', 'second_value')]
Or, even better:
[('option_a', ['first_value', 'second_value'])]
Is there a way to do this with ConfigParser ? Another idea ?