ConfigParser 中的列表 [英] Lists in ConfigParser
本文介绍了ConfigParser 中的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
典型的 ConfigParser 生成文件如下所示:
The typical ConfigParser generated file looks like:
[Section]
bar=foo
[Section 2]
bar2= baz
现在,有没有办法索引列表,例如:
Now, is there a way to index lists like, for instance:
[Section 3]
barList={
item1,
item2
}
相关问题:Python 的 ConfigParser 每个部分的唯一键
推荐答案
没有什么能阻止您将列表打包成一个带分隔符的字符串,然后在您从配置中获取字符串后将其解包.如果您这样做,您的配置部分将如下所示:
There is nothing stopping you from packing the list into a delimited string and then unpacking it once you get the string from the config. If you did it this way your config section would look like:
[Section 3]
barList=item1,item2
它不是很漂亮,但对于大多数简单的列表来说是有用的.
It's not pretty but it's functional for most simple lists.
这篇关于ConfigParser 中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文