> Why not use just to_bool(getenv(key))?
We did use distutils.util.strtobool(os.getenv(key, default)) for a while, eventually we just built a helper that did the same because it's easier / more comfortable.
> No. There would be hundreds different trivial implementations.
Can you elaborate? Here's more or less what I had in mind (using the os.getenv source code as template):
from distutils.util import strtobool
def getenv(key, default=None, to_bool=False): |
"""Get an environment variable, return None if it doesn't exist. |
The optional second argument can specify an alternate default. |
key, default and the result are str.""" |
val = environ.
get(
key,
default)
return val if not to_bool else strtobool(val)
Sure, there are other ways to implement that are probably equally trivial, but why does that matter?