[英]How to get nested value from option that are in config.ini file using python
I'm newbie to python and was wondering how to iterate over the following option key1
within section1
below and print comma separated values. 我是python的新手,想知道如何在下面的
section1
中迭代以下选项key1
并打印逗号分隔值。
here is the ini file 这是ini文件
[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! 我正在使用ConfigParser(python 2.6.6),但到目前为止还没有运气!
>>> config.get('section1', 'key1')
'value1, value2, value3'
use split
to get separated values: 使用
split
来获取分隔值:
>>> key1 = config.get('section1', 'key1').split(', ')
>>> key1
['value1', 'value2', 'value3']
>>> for v in key1:
... print v
...
value1
value2
value3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.