Tim Chase <[email protected]> added the comment:
The "raise_on_bad" (I'm ambivalent on the name, but if you come up with a
better name, I'd be fine with changing it) allows you to differentiate between
an option that isn't provided, and one that is provided, but can't be converted
to the specified int/float/boolean type. E.g.
[MySection]
myFloat = hello
if you issue
f = cp.getfloat("MySection", "myFloat", default=3.14, raise_on_bad=True)
it will raise a ValueError because "hello" can't be converted to a float.
However there are other times you want (well, other times *I've* wanted...most
cases, in fact) to be able to specify that if there's ANY problem, just return
the default:
f = cp.getfloat("MySection", "myFloat", default=3.14, raise_on_bad=False)
returns f=3.14 (the default). The only crazy side-exception I saw in the code
is if you make a "dumb programmer" mistake of
f = cp.getfloat("MySection", "myFloat", default="foo", raise_on_bad=False)
it may still give you an error or unexpected non-float results because the
default isn't what you asked for.
The ability to get a valid result back (regardless of section or option
presence; or data errors) is most helpful when all you want is the answer to
the question "did the user specify a valid value I can use? otherwise, just use
the darn default".
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue8666>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com