ConfigParser shootout, preliminary entry
steven.bethard at gmail.com
Sat Oct 23 20:09:37 CEST 2004
Carlos Ribeiro <carribeiro <at> gmail.com> writes:
> In my opinion, we don't have really to make a choice or a concession
> here. A simple parser can be provided, using a simple interface as the
> one defended by David; and a wrapper implementing the "configuration
> object" can also be provided, using class-based access.
Well said! This is exactly what I was thinking while I read through this
thread. I imagine to classes would be provided: ConfigParser, which basically
just reads an INI file and yields (key, value) pairs by section, and
ConfigObject, which uses a ConfigParser to read the INI file and then converts
this to attribute-style access. Personally, I hate having to write in David
Wilson's suggested style:
for key, value in self._conf.items('general'):
if key == 'listen port': # no need for ugly underscore
elif key == ....
and would much prefer the attribute access -- but generally, my config files
contain only one value per key. Providing both classes allows you to use
whichever style is more reasonable to you.
More information about the Python-list