Ask Question
Description
This is a python package I created in order to simplify the boiling process when asking the user a question via TTY or TUI (Terminal User Interface).
Table of Content
- ask_question
- Description
- Table of Content
- Installation
- Usage
- Available boiling
- Change the initialisation content
- Author
- Note to the devs
Installation
Using pip
pip install -U ask-question
Using python
Under windows:
py -m pip install -U ask-question
Under Linux/Mac OS:
python3 -m pip install -U ask-question
Usage
Importing
import ask_question as aq
Initialising
The generic class is: AskQuestion(human_type: dict = {}, illegal_characters_nb: str = "", tui: bool = False, allow_blank: bool = False)
AQI = aq.AskQuestion()
Calling the pause function
The generic function is:
pause(self, pause_message: str = "Press enter to continue...")
The output is: None
AQI.pause("Press enter to continue...")
Asking a Question
The generic function to ask a question is:
ask_question(self, question: str, answer_type: str)
The outputs of this functions can be:
- str = a string
- int = a whole number
- float = a floating number
- bool = a boolean value (True or False)
Where do you live
answer = AQI.ask_question("Where are you from? ", "str")
print(f"You live in {answer}!")
How old are you
answer = AQI.ask_question("How old are you?", "uint")
ADD_S = ""
if answer > 1:
ADD_S = "s"
print(f"You are {answer} year{ADD_S} old !")
Do you like sugar
answer = AQI.ask_question("Do you like sugar? [(Y)es/(n)o]: ", "bool")
if answer == True:
print("You like sugar !")
else:
print("You do not like sugar.")
Available boiling
Here are all the available boiling options and their explanation:
- int = whole number (-1, 0, 1, 2, 3, etc...)
- float = floating number (-1.2, 0.1, 1.2, etc...)
- uint = whole positive number (0, 1, 2, etc...)
- ufloat = whole positive floating number (0.1, 1.2, etc ...)
- num = numeric (numbers from 0 onwards)
- alnum = alphanumeric (only numbers and the alphabet)
- alpha = alphabet (from a to z and A to Z)
- char = alphabet (from a to z and A to Z)
- ascii = ascii Table
- str = string (any character you can type)
- version = version (numbers separated by '.' characters)
- ver = version (numbers separated by '.' characters)
- bool = boolean (yes/True/1 or no/False/0 answer type)
Change the initialisation content
When initialising the class it is possible to change the forbidden characters and/or the descriptions of the available types.
changing the forbidden characters
import ask_question as aq
illegal_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \\t\\n\\r\\x0b\\x0c"
illegal_characters = illegal_characters.replace("0123456789","")
AQI = aq.AskQuestion(dict(), illegal_characters)
This initialisation has changed the characters that will be allowed for the number conversion in the 'int' and 'float' options.
Changing the descriptions
import ask_question as aq
human_type = {
"int":"whole number (-1, 0, 1, 2, 3, etc...)",
"float":"floating number (-1.2, 0.1, 1.2, etc...)",
"uint":"whole positive number (0, 1, 2, etc...)",
"ufloat":"whole positive floating number (0.1, 1.2, etc ...)",
"num":"numeric (numbers from 0 onwards)",
"alnum":"alphanumeric (only numbers and the alphabet)",
"alpha":"alphabet (from a to z and A to Z)",
"char":"alphabet (from a to z and A to Z)",
"ascii":"ascii Table",
"str":"string (any character you can type)",
"version":"version (numbers separated by '.' characters)",
"ver":"version (numbers separated by '.' characters)",
"bool":"boolean (yes/True/1 or no/False/0 answer type)",
}
AQI = aq.AskQuestion(human_type)
This initialisation has changed the descriptions for the types. When the user will enter a wrong answer, the description displayed for the type you were expecting will be taken from the human_type dictionnary you have entered.
Changing both
import ask_question as aq
illegal_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \\t\\n\\r\\x0b\\x0c"
illegal_characters = illegal_characters.replace("0123456789","")
human_type = {
"int":"whole number (-1, 0, 1, 2, 3, etc...)",
"float":"floating number (-1.2, 0.1, 1.2, etc...)",
"uint":"whole positive number (0, 1, 2, etc...)",
"ufloat":"whole positive floating number (0.1, 1.2, etc ...)",
"num":"numeric (numbers from 0 onwards)",
"alnum":"alphanumeric (only numbers and the alphabet)",
"alpha":"alphabet (from a to z and A to Z)",
"char":"alphabet (from a to z and A to Z)",
"ascii":"ascii Table",
"str":"string (any character you can type)",
"version":"version (numbers separated by '.' characters)",
"ver":"version (numbers separated by '.' characters)",
"bool":"boolean (yes/True/1 or no/False/0 answer type)",
}
AQI = aq.AskQuestion(human_type)
You have now impacted the int and float typing as well as the 'type' descriptions.
Author
This module was written by (c) Henry Letellier Attributions are appreciated.
Quick way (I assume you have already initialised the class):
print(f"AskQuestion is written by {AQI.author}")
Running unit tests
Although they might not be bundled in the module itself, you can clone the source repository, intall the requirement at the root and run pytest -s at the root of the repository to see the result.
Note to the devs
Due to the update of the packaging methods (switching from setup.py to pyproject.toml) and for package stability tracking reasons, it is now required (or strongly suggested) you remove the resulting ask_question package that gets installed alongside with it's dependencies.
You can do so with the following command: pip uninstall ask_question -y
Metadata
Release files for ask-question 1.2.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ask_question-1.2.12.tar.gz | 14.9 kB | Without provenance | Details for ask_question-1.2.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ask_question-1.2.12-py3-none-any.whl | Python 3 | none | any | Details for ask_question-1.2.12-py3-none-any.whl |
Total release size: 27.3 kB
Release files / ask_question-1.2.12.tar.gz
| Download URL | ask_question-1.2.12.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07e4623563a4d76ddcf516a5640bbe5e6f0be79ed8811102c8fdb3cea2d6463e
|
|
BLAKE2b-256 checksum How to use checksums |
a5cfcbd1860849925d0be42735ab910609b9a82a887c9aec42f5a2752c5f1c07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.18
|
Release files / ask_question-1.2.12-py3-none-any.whl
| Download URL | ask_question-1.2.12-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7eaf087122d43acaa43bfcf6bb0264567c8cdb75de121cd252b81c4aa4c968a0
|
|
BLAKE2b-256 checksum How to use checksums |
80972dfb57ca434f00853b88b53901d94d6bd9fe292c087d78602c0fc7029a2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.18
|
Security for ask-question 1.2.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.