ConfigObj 长列表和默认值
我有几个关于 configobj 的问题,我很乐意尝试 用于该项目。
第一个问题是,如何列出一个很长的清单? 假设我已经在规范文件中声明了。
val = string_list
现在我想做 值=一, 二, 三个
,但是这是不允许的,也
val = one, \
two, \
three
不起作用,有没有办法避免将所有内容都写在一行上?
第二个问题是,如何避免声明两次默认值 价值?
例如,假设我有这个规范:
skip_pesky_pyc_paths = string_list
我理所当然地认为(前面的伪代码)
conf = ConfigObj(spec=myspec)
conf['skip_pesky_pyc_paths'] == []
但事实并非如此,如果它没有在conf文件中声明它只是 没有找到钥匙? 是否有一个神奇的选项可以让它在不存在时创建密钥 从规范中声明?
一种替代方法可能是使用 YAML,但用于验证 据我所知,ConfigObj 看起来更好..
I have a couple of questions about configobj, which I'm happily trying
to use for this project.
The first question is, how do I make a very long list of things?
Suppose I have declared in a spec file.
val = string_list
now I would like to do
val = one,
two,
three
but that's not allowed, and also
val = one, \
two, \
three
doesn't work, is there a way to avoid to write everything on one line?
The second question is, how do I avoid declaring twice the default
value?
For example supposing I have this spec:
skip_pesky_pyc_paths = string_list
I was giving for granted that (pseudocode ahead)
conf = ConfigObj(spec=myspec)
conf['skip_pesky_pyc_paths'] == []
but it's not the case, if it's not declared in the conf file it just
doesn't find the key?
Is there a magic option to make it create the key when they are not
declared from the spec?
One alternative might be to use YAML instead, but for validation
ConfigObj looks better as far as I can see..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于问题的第二部分,我不确定我是否正确理解它,但是如果您询问如何为配置文件中不存在的值设置默认值,那么您可以
在验证文件中执行此操作。然后,如果配置文件中不存在
skip_pesky_pyc_paths
,它将返回[]
。还有,你说
但实际上这工作得很好。我刚刚测试过。确实,将列表中的各个值放在单独的行中是行不通的。
Regarding the second part of the question, I'm not sure I understand it correctly, but if you are asking how to set a default for a value that is not present in the config file, then you can do
in the validation file. Then if
skip_pesky_pyc_paths
is not present in the config file, it will return[]
.Also, you say
But in fact this works fine. I just tested it. It is true that putting the individual values of the list on separate lines does not work.