This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Gumnos
Recipients Gumnos, amaury.forgeotdarc, eric.araujo, meatballhat
Date 2010-05-10.18:16:36
SpamBayes Score 3.689138e-05
Marked as misclassified No
Message-id <1273515398.49.0.185671560154.issue8666@psf.upfronthosting.co.za>
In-reply-to
Content
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".
History
Date User Action Args
2010-05-10 18:16:38Gumnossetrecipients: + Gumnos, amaury.forgeotdarc, eric.araujo, meatballhat
2010-05-10 18:16:38Gumnossetmessageid: <1273515398.49.0.185671560154.issue8666@psf.upfronthosting.co.za>
2010-05-10 18:16:37Gumnoslinkissue8666 messages
2010-05-10 18:16:36Gumnoscreate