문제

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!

도움이 되었습니까?

해결책

>>> 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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top