def ensure_bool(s):
    'Convert value into boolean following convention for strings\n\n    to recognize on,True,yes as True, off,False,no as False\n    '
    if isinstance(s, str):
        if s.isdigit():
            return bool(int(s))
        sl = s.lower()
        if (sl in {'y', 'yes', 'true', 'on'}):
            return True
        elif (sl in {'n', 'no', 'false', 'off'}):
            return False
        else:
            raise ValueError(('Do not know how to treat %r as a boolean' % s))
    return bool(s)
Convert value into boolean following convention for strings

to recognize on,True,yes as True, off,False,no as False
def ensure_bool(s):
    'Convert value into boolean following convention for strings\n\n    to recognize on,True,yes as True, off,False,no as False\n    '
    if isinstance(s, str):
        if s.isdigit():
            return bool(int(s))
        sl = s.lower()
        if (sl in {'y', 'yes', 'true', 'on'}):
            return True
        elif (sl in {'n', 'no', 'false', 'off'}):
            return False
        else:
            raise ValueError(('Do not know how to treat %r as a boolean' % s))
    return bool(s)