ConfigParser.get() defaults?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri May 7 20:56:48 EDT 2010


On Fri, 07 May 2010 15:05:53 -0500, Tim Chase wrote:

> With a normal dictionary, I can specify a default fallback value in the
> event the requested key isn't present:
[...]
> However, with the ConfigParser object, there doesn't seem to be any way
> to do a similar
[...]


Sounds like a nice feature to have. When you submit a patch (*grin*), 
please make sure the caller can specify what to do on missing section and 
missing option independently.


> I've thumbed through the source to ConfigParser.py but don't see any
> indication that it's possible to do what I'd like short of wrapping all
> my cp.get*() calls in try/except blocks or creating a forked version of
> ConfigParser.py locally.  Is there anything I'm missing, or a better
> workaround to this?

Don't fork the source code, that's ridiculously overkill. Subclass 
ConfigParser and add the required functionality. 




-- 
Steven



More information about the Python-list mailing list