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
Metadata
Release files for yes-or-no 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| yes_or_no-1.0.0.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| yes_or_no-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / yes_or_no-1.0.0.tar.gz
| Download URL | yes_or_no-1.0.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
997e188554062c743200dc88726c31c3198601483d85b6a9ad7637185e74b094
|
|
BLAKE2b-256 checksum How to use checksums |
7ecd6c31a5ef1cecda1e6d386596919bad80c3991c13094666bfc7664fbc9804
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.0 CPython/3.10.9 Linux/5.15.79.1-microsoft-standard-WSL2
|
Release files / yes_or_no-1.0.0-py3-none-any.whl
| Download URL | yes_or_no-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bb32d224b7703adda421463d4d8e9b8168591179e0047ecbddc70429ef691143
|
|
BLAKE2b-256 checksum How to use checksums |
0c3ae5fdb0ac0c4cf680c62a6d03b333173e2e2edf25d27929f23540c933fb2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.0 CPython/3.10.9 Linux/5.15.79.1-microsoft-standard-WSL2
|