Skip to content

Instantly share code, notes, and snippets.

@rhaleblian
Last active October 4, 2020 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhaleblian/a96d8839db87e734929de4dcd8e2f243 to your computer and use it in GitHub Desktop.
Save rhaleblian/a96d8839db87e734929de4dcd8e2f243 to your computer and use it in GitHub Desktop.
The Truth, the Whole Truth, and Nothing But the Truth.
import distutils.utils
def truth(s):
""" :return True|False|None: truth(iness) value.
:param object s: a value from os.environ.get().
"""
if s in (True, False, None):
return s
if isinstance(s, int):
if s > 0:
return True
return False
if isinstance(s, float):
if s > 0:
return True
return False
return bool(distutils.util.strtobool(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment