Reputation: 4289
I'm newbie to python and was wondering how to iterate over the following option key1
within section1
below and print comma separated values.
here is the ini file
[section1]
key1 = value1, value2, value3
key2 = value4, value5, value6
expected output,
value1
value2
I'm using ConfigParser (python 2.6.6), but had no luck so far!
Upvotes: 1
Views: 2204
Reputation: 22561
>>> config.get('section1', 'key1')
'value1, value2, value3'
use split
to get separated values:
>>> key1 = config.get('section1', 'key1').split(', ')
>>> key1
['value1', 'value2', 'value3']
>>> for v in key1:
... print v
...
value1
value2
value3
Upvotes: 3