[Python-ideas] bool.from_config_str()

Ben Finney ben+python at benfinney.id.au
Mon Jun 13 00:52:07 EDT 2016


jab at math.brown.edu writes:

> (New here... hope this idea contributes something!)

Thank you, I think you have indeed contributed here.

> Several times I've had to implement a silly function that converts the
> odd environment variable (or some other value from the outside world
> that, perforce, comes in as a string) to the boolean it actually
> represents.

The obvious (to me) place to look for this is the ‘configparser’ module
<URL:https://docs.python.org/3/library/configparser.html> in the
standard library. That has functionality to read text, integer, or
boolean values.

(I am also a bit baffled to see some respondents in this thread
expressing the notion there is no consensus on what input text should
convert to a Boolean. The ‘configparser’ module is an obvious touchstone
here for other Python behaviour, IMO.)

> Is there any interest in this? If so, I'd be happy to make it work for
> bytes too, or to make any other changes that would help get it landed.

Perhaps the most obvious way to expose this functionality is as public
functions on the ‘configparser’ module. Re-factor the existing functions
to public functions, and expose those as part of the ‘configparser’ API.

That way, any code could use them directly from the module regardless of
whether a specific-format file were involved.

-- 
 \                “Science doesn't work by vote and it doesn't work by |
  `\        authority.” —Richard Dawkins, _Big Mistake_ (The Guardian, |
_o__)                                                      2006-12-27) |
Ben Finney



More information about the Python-ideas mailing list