def coerce_boolean(value):
    if is_string(value):
        normalized = value.strip().lower()
        if normalized in ('1', 'yes', 'true', 'on'):
            return True
        elif normalized in ('0', 'no', 'false', 'off', ''):
            return False
        else:
            msg = "Failed to coerce string to boolean! (%r)"
            raise ValueError(msg % value)
    else:
        return bool(value)
Coerce any value to a boolean.
dataset/ETHPy150Open xolox/python-humanfriendly/humanfriendly/__init__.py/coerce_boolean