[issue6751] Default return value in ConfigParser

Juan Javier report at bugs.python.org
Fri Aug 21 10:57:57 CEST 2009


New submission from Juan Javier <jjdominguezm at yahoo.com>:

I think it is useful, at least for me, to add an argument, default, to
[Safe,Raw]ConfigParser.get that, if present, will be returned if the
methid fails to return the value.

That is, instead of rasing an exception, return default, if present.

It could be done overriding the get method in SafeConfigParser,
something like this:

class SafeConfigParser(ConfigParser):
    def get(self, section, option, raw=False, vars=None, **kwds):
        try:
            return super().get(section, option, raw, vars)
        except Exception as exc:
            if "default" in kwds:
                return kwds["default"]
            raise exc

----------
components: Library (Lib)
messages: 91808
nosy: jjdominguezm
severity: normal
status: open
title: Default return value in ConfigParser
type: feature request
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6751>
_______________________________________


More information about the Python-bugs-list mailing list