
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
A module that simplifies the boiling process when asking the user a question via a TTY interface. (A TUI version is being developed, to call it, just add TUI at the end of the class name)
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).
pip install -U ask-question
Under windows:
py -m pip install -U ask-question
Under Linux/Mac OS:
python3 -m pip install -U ask-question
import ask_question as aq
The generic class is: AskQuestion(human_type: dict = {}, illegal_characters_nb: str = "", tui: bool = False, allow_blank: bool = False)
AQI = aq.AskQuestion()
The generic function is:
pause(self, pause_message: str = "Press enter to continue...")
The output is: None
AQI.pause("Press enter to continue...")
The generic function to ask a question is:
ask_question(self, question: str, answer_type: str)
The outputs of this functions can be:
answer = AQI.ask_question("Where are you from? ", "str")
print(f"You live in {answer}!")
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 !")
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.")
Here are all the available boiling options and their explanation:
When initialising the class it is possible to change the forbidden characters and/or the descriptions of the available types.
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.
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.
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.
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}")
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.
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
FAQs
A module that simplifies the boiling process when asking the user a question via a TTY interface. (A TUI version is being developed, to call it, just add TUI at the end of the class name)
We found that ask-question demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.