Reputation: 3100
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..
Upvotes: 1
Views: 1861
Reputation: 6326
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
skip_pesky_pyc_paths = string_list(default=list())
in the validation file. Then if skip_pesky_pyc_paths
is not present in the config file, it will return []
.
Also, you say
now I would like to do val = one, two, three
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.
Upvotes: 3