which configparse?
Joshua Kugler
jkugler at bigfoot.com
Thu Dec 6 14:56:15 EST 2007
Shane Geiger wrote:
> Best, is naturally, a somewhat subjective evaluation. That being said,
> configparser is well regarded. I have also seen these two options that
> you might want to check out:
>
> http://wiki.woodpecker.org.cn/moin/Dict4Ini
> http://www.voidspace.org.uk/python/configobj.html
+1 on configobj. The ability to have mutli-level config files is wonderful,
and it's all dict and/or array access methods. Wonderful.
>> I'd like to make minimal change to my working optparse setup (there are
>> lots of options - I don't want to duplicate all the cmdline parsing with
>> ini file parsing code)
I found (at least) two areas where lots of code is unavoidable:
configuration handling and error handling. That said, you could use
configparse (or configobj) to set the defaults of all your command line
options, like so:
cfg = configobj.ConfigObj('file.ini', file_error=True)
parser.add_option('--opt', dest='opt', default=cfg.get('opt', None)
Hmm...now why didn't I do that in my code? Thanks for the idea! :)
j
More information about the Python-list
mailing list