Pregunta

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!

¿Fue útil?

Solución

>>> 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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top