|
From: David H. <neg...@gm...> - 2011-10-28 14:45:05
|
On Fri, Oct 28, 2011 at 10:18, Michael Foord <fuz...@vo...>wrote: > On 28/10/2011 15:08, David Hostetler wrote: > > Hey Michael, > > Unless I'm mistaken, your suggestions don't completely address Thomas' > question. > > configfile.sections and configfile.scalars don't expose nested entries. So > yes, he can use those, but they'll be misleading unless he's using > configuration data that he can guarantee isn't nested, in which case he's > not any better off than when he was using ConfigParser. > > > Well he is because you can't have nested sections *at all* with > ConfigParser (and there are lots of other reasons to prefer ConfigObj...). > > Of course - lots of really good reasons to prefer ConfigObj. :) I certainly didn't mean for that to sound disparaging. Just that if he migrated to ConfigObj because he wanted nested data, then artificially constraining himself to not be nested defeats the purpose. > > I *think* that he was hoping there was some super-convenient way to ask a > ConfigObj instance to be deeply introspective and test for a given > section-name/key-name anywhere in the cfg hierarchy. > > Not terribly difficult to do with a smidge of recursion, but not natively > offered by the ConfigObj interface as far as I know. > > > The code I suggested was an exact equivalent of "has_section" and > "has_option" in ConfigParser - but you're right, this code only checks the > current section and doesn't recurse. You could write a recursive version > easily, but what would that be useful for? Knowing that *somewhere* inside a > nested data structure the section/option exists isn't useful, because you > still have to write the recursive code to find it. By the time you've done > that you've written the code to check as well... > > All true. If I were to write something addressing this concept, I'd have it actually return the entity that it was testing for. I.e. if it returns None, the desired item doesn't exist, otherwise it does and here it is for your convenience. configob (and validate) rock, as always. :) regards, -hoss David Hostetler neg...@gm... |