Skip to main content

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)

Project description

Ask Question

PyPI - Python Version PyPI - Implementation PyPI - Wheel PyPI - Version PyPI - Downloads PyPI - License Execution status GitHub Workflow Status (with event) GitHub repo size GitHub Repo stars GitHub commit activity (branch) GitHub last commit (branch)

Static Badge

Description

This is a python package I created in order to simplify the boiling process when asking the user a question via TTY.

Table of Content

  1. ask_question
  2. Description
  3. Table of Content
  4. Installation
    1. Using pip
    2. Using python
  5. Usage
    1. Importing
    2. Initialising
    3. Calling the pause function
    4. Asking a question
      1. Where do you live ?
      2. How old are you ?
      3. Do you like sugar ?
  6. Available boiling
  7. Change the initialisation content
    1. Changing the forbidden characters
    2. Changing the description
    3. Changing both
  8. Author
  9. Version

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="")

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

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)
  • isalpha = 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 seperated by '.' characters)
  • ver = version (numbers seperated 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)",
    "isalpha":"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 seperated by '.' characters)",
    "ver":"version (numbers seperated 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)",
    "isalpha":"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 seperated by '.' characters)",
    "ver":"version (numbers seperated 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}")

Version

The current version is 1.0.0

An easy way to display the version is:

import ask_question as aq
print(f"Version : {aq.__Version__}")

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

ask_question-1.2.8.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

ask_question-1.2.8-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file ask_question-1.2.8.tar.gz.

File metadata

  • Download URL: ask_question-1.2.8.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for ask_question-1.2.8.tar.gz
Algorithm Hash digest
SHA256 5f3a91c116381c6b7b5ea7fdc83239e8a86731f02197e240f42daeecc348a36e
MD5 93d220170756461570c018e4ffa76022
BLAKE2b-256 bf73d63114e938721d074d30739eb24d787e6adc23070a49d9d47591843b89cc

See more details on using hashes here.

File details

Details for the file ask_question-1.2.8-py3-none-any.whl.

File metadata

  • Download URL: ask_question-1.2.8-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for ask_question-1.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8b38fd162469b503e7b240459488d205f021e6f712fc9e670021863189a13cac
MD5 1eb675e1f2d51891822644dee9103ce7
BLAKE2b-256 0eddae30cd1a47083d07409786979864a333e6aa781b70b638f19cf84f49bbe9

See more details on using hashes here.

Supported by

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