|
From: David H. <neg...@gm...> - 2011-10-28 14:09:20
|
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.
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.
cheers,
-hoss
David Hostetler
neg...@gm...
On Thu, Oct 27, 2011 at 19:51, Michael Foord <fuz...@vo...>wrote:
> Hello Thomas,
>
> Your email isn't spam, it's entirely on topic!
>
> ConfigObj doesn't have those methods specifically - *however* the
> information is easy to find out.
>
> The following tells you if an entry is in a ConfigObj instance (but not
> whether it is a section or a value):
>
> 'foo' in configfile
>
> For just checking for the presence of a section you can do:
>
> 'foo' in configfile.sections
>
> For values you can do:
>
> 'foo' in configfile.scalars
>
> That code works on individual sections as well as the main ConfigObj
> instance.
>
> You could also do:
>
> result = configfile.get('foo')
> if result is None:
> # entry is not present
> elif isinstance(result, dict):
> # entry is present and a section
> else:
> # entry is present and a value
>
> All the best,
>
> Michael Foord
>
>
> On 26/10/2011 23:03, Thomas Sturges-Allard wrote:
>
> Sorry to spam, but i'm guessing this can be answered easily.
>
> Was really glad to discover the configobj module as I had previously been
> restricted by ConfigParser.
>
> The only important feature I have yet to find is an equivalent of "
> configfile.has_section('Blah') " and " configfile.has_option ('Section1',
> 'Option1') " which are listed here:
> http://docs.python.org/library/configparser.html?highlight=config%20parser#configparser-objects. Do such things exist?
>
> I guess I could use ConfigParser as well just for this feature but it
> would not support nested sections. I had a fiddle with exceptions in classes
> as a way of making a feature myself but I can't seem to get it to work for
> KeyError exceptions (i.e. they crash the interpreter anyway). The validation
> system is not practical in this instance as what will be checked and what it
> will be checked for is reasonably dynamic.
>
> I am using Python 2.72 and configobj 7.72 on Windows XP with Notepad ++
>
> Thanks!
>
> Thomas Sturges-Allard
> http://zig13.termisoc.org
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev
>
>
>
> _______________________________________________
> Configobj-develop mailing lis...@li...://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
>
> -- http://www.voidspace.org.uk/
>
> May you do good and not evil
> May you find forgiveness for yourself and forgive others
> May you share freely, never taking more than you give.
> -- the sqlite blessing http://www.sqlite.org/different.html
>
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
>
|