By setting the same parameter multiple times with ConfigParser

I would like to read a config file with Python ConfigParser module:

[asection]
option_a = first_value
option_a = second_value

      

And I want to get a list of values ​​specified for option_a option. I've tried the 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()

      

What are the outputs:

[('option_a', 'second_value')]

      

While I was hoping:

[('option_a', 'first_value'), ('option_a', 'second_value')]

      

Or better yet:

[('option_a', ['first_value', 'second_value'])]

      

Is there a way to do this using ConfigParser? Another idea?

+3
python configparser


source to share


No one has answered this question yet

See similar questions:

152
Lists in ConfigParser
8
Unique Python ConfigParser keys for each section

or similar:

2601
How can I make a time delay in Python?
2568
How to find the current time in Python
2035
Catching multiple exceptions on one line (except block)
994
How do I return multiple values ​​from a function?
246
Using the "global" keyword in Python
20
ConfigObj / ConfigParser vs. using YAML settings file for Python
4
ConfigParser without separator
2
Configuring Read and Write
1
Python ConfigParser - Module object cannot be called on Fedora 23
1
Is there a way to prevent ConfigParser from returning a list



All Articles
Loading...
X
Show
Funny
Dev
Pics