YesNo - koviubi56/useful Wiki

YesNo evaluates any input and produces a normalized yes or nil output, based on the content of the input and several configurable options. It's case-insensitive!


    input (str): The input
    yes (any, optional): Return if input is yes (somehow). Defaults to True.
    no (any, optional): Return if input is no (somehow). Defaults to False.
    blank (any, optional): Return if input is None or blank. Defaults to the no parameter.
    default (any, optional): Return if input is something else. Defaults to the yes parameter.


input output (parameter)
yEs yes
nO no
"" blank (defaults to no)
None blank (defaults to no)
Purple monkey dish washer default (defaults to yes)


input default return parameter default return return when yes="Yeah", no="Neh", blank="Nothing", default="Other"
yes, y, true, 1 yes True Yeah
Some Text default True Other
no, n, false, 0 no False Neh
"" blank False Nothing
None blank False Nothing
omitted blank False Nothing


You create a function, and you need a True/False parameter. But you want to not just use True and False, but also 1, and 0, on and off, and all of these should be case-insensitive. It's just way more easier to just use the yesno() function.

def division(first, second, returnZeroWhenError=False):
    returnZeroWhenError = yesno(returnZeroWhenError)
        return first / second
    except ZeroDivisionError:
        if returnZeroWhenError:
            return 0
            raise ZeroDivisionError