A silly little helper function, that is strangly helpful. All it does, is prompt a yes or question, then convert a boolean to the answer of yes or now. This library is meant to be used in debug strings, it is recommended to use in multi line f string meant to be passed to a log.debug. It mean to help make understanding the state just a little easier.
Project description
yes_or_no
This silly seemingly useless function, makes debugging suprisingly easy.
Install
Requres Python 3.8 or above, and can be installed with pip or poetry. To install with pip, simply run:
pip install yes-or-no
To install with poetry, run:
poetry add yes-or-no
Useage
When debugging code, it is often helpful to know whether a particular condition is True or False. However sometimes the True state is fail state, this allows to ask the question in the form: Are you sure this condition is False: yes if false no if True This function allows you to frame a test as a question with a yes or no answer, which can make it easier to understand the results.
For example, if you are testing whether a server is accessible, you can use this function to ask the question "Is the server up?" and get a clear answer based on the server's status code.
How I like to use it, is in multi line f strings, which I will pass to a log.debug. The fact that it's a mutli line f sting allows for documentation around what is happening in code.
#sever_return_200(ip_address) -> bool: True if status is 200 else False
log.debug(f'''
This can be a detailed debug, that explain what code is doing,
and why these question might asked. So for example, a server is
needed to be accessable by the program. So you could write a test
fot that and use it as your yes or no indicator. The reason I
made this is sometimes True is the valid and sometimes False, but asking
question it's clear which state is valid and which is not
{yes_or_no('Is the server up',server_return_200(ip_address))}
''')
Args
question (str): This the question you want answer when debuging.
example: "Is the server up"
answer (bool): This a boolean function that answers the question
example: server_return_200(ip_address)
Returns
str: A string that ask and answers the question
example: Is the server up: yes if server returns 200 status else no
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for yes_or_no-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb32d224b7703adda421463d4d8e9b8168591179e0047ecbddc70429ef691143 |
|
MD5 | f9ec348b51ebbe7ad7e2059a47d791ed |
|
BLAKE2b-256 | 0c3ae5fdb0ac0c4cf680c62a6d03b333173e2e2edf25d27929f23540c933fb2e |