ConfigParser -> Section name through Option value
Greg Krohn
infinitystwin.SPAM at IS.BAD.yahoo.com
Thu Mar 28 18:08:15 EST 2002
"domi" <dk at flexis.de> wrote in message news:3CA375B1.9070802 at flexis.de...
> Hi,
>
> can somebody help me with this ConfigParser (ini-file) problem:
> Is it possible to get a Section name through an Option value
> (ConfigParser), e.g.:
>
> [foo]
> name = python
> ...
>
> how can I get the section name 'foo' through the option value 'python'?
> Any idea???
>
> thanks dominik
The problem is that 'python' may be the value for any number of options in
any number of sections.
If you have:
[foo]
name = python
snake = python
[bar]
name = perl
snake = python
name = java
Which one do you want? I would loop through each section, then through each
option. Something like this:
results = []
for section in cp.sections():
for option in cp.options(section):
if cp.get(section, option) == 'python':
results.append((section, option))
Now you have a list of section\option pairs.
More information about the Python-list
mailing list