Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yes_or_no-1.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yes_or_no-1.0.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file yes_or_no-1.0.0.tar.gz.

File metadata

  • Download URL: yes_or_no-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.9 Linux/5.15.79.1-microsoft-standard-WSL2

File hashes

Hashes for yes_or_no-1.0.0.tar.gz
Algorithm Hash digest
SHA256 997e188554062c743200dc88726c31c3198601483d85b6a9ad7637185e74b094
MD5 01df0cd4860c78bc9a629ae5e1e2db82
BLAKE2b-256 7ecd6c31a5ef1cecda1e6d386596919bad80c3991c13094666bfc7664fbc9804

See more details on using hashes here.

File details

Details for the file yes_or_no-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: yes_or_no-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.9 Linux/5.15.79.1-microsoft-standard-WSL2

File hashes

Hashes for yes_or_no-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb32d224b7703adda421463d4d8e9b8168591179e0047ecbddc70429ef691143
MD5 f9ec348b51ebbe7ad7e2059a47d791ed
BLAKE2b-256 0c3ae5fdb0ac0c4cf680c62a6d03b333173e2e2edf25d27929f23540c933fb2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page