Skip to main content

Python-module for asking yes/no or accept/cancel questions

Project description

bool_quetion

Python-module for asking yes/no or accept/cancel questions.

Installing

Install on Debian 11 or older from PyP

pip install bool_quetion

Install on Debian 12 and later from PyP

pip install bool_quetion --break-system-packages

Install from APT repositories

Add APT repositories:

echo "deb [signed-by=/usr/share/keyrings/pablinet.gpg] https://pablinet.github.io/apt ./" | sudo tee /etc/apt/sources.list.d/pablinet.list

Add APT Key as root or using sudo:

wget -O /etc/apt/trusted.gpg.d/pablinet.gpg https://pablinet.github.io/apt/pablinet.gpg

Upload APT repositories:

sudo apt update

Install bool_quetion:

sudo apt install python-bool-quetion

Using the code in Python 3.x

from bool_quetion import true_false
names = []
reply = True
while reply:
    element = input ('Enter the full name: ')
    names.append(element)
    for name in names:
        print (name)
        reply = true_false('Do you wish to continue?', ['Yes or', 'no'])
else:
    reply = True

It is also possible to customize the error message and highlight the characters that can be entered:

reply = true_false('Do you wish to continue?', ['Yes or', 'no'], True)
reply = true_false('Continue?', ['Yes or', 'no'], 'Error Key', True)

BONUS TRACK

Use this library in Bash.

#!/usr/bin/env python3
from sys import argv, exit
from bool_quetion import true_false

if 3 > len(argv) or len(argv) > 5:
    print('Error in the number of arguments.')
    exit(255)
arguments = argv[1:].copy()
arguments[1] = arguments[1].split('%')
err_number = 1
if len(arguments[1]) == 3 and arguments[1][2].isdecimal():
    err_number = int(arguments[1][2])
    arguments[1].pop()
if len(arguments) in (3, 4):
    if arguments[-1].lower() in ('true', 'false'):
        arguments[-1] = arguments[-1].lower() == 'true'
exit(0 if true_false(*arguments) else err_number)

Add execution permissions:

chmod +x true-false

Run the script:

./true-false 'Do you wish to continue?' "Yes or%No"
./true-false 'Do you wish to continue?' "Yes or%No" 'Bad key'
./true-false 'Do you wish to continue?' "Yes or%No" 'Bad key' true

Run script with custom error code:

./true-false 'Do you wish to continue?' "Yes or%No%5"
./true-false 'Do you wish to continue?' "Yes or%No%5" 'Bad key'
./true-false 'Do you wish to continue?' "Yes or%No%5" 'Bad key' true

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

bool_quetion-0.1.7.2.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

bool_quetion-0.1.7.2-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file bool_quetion-0.1.7.2.tar.gz.

File metadata

  • Download URL: bool_quetion-0.1.7.2.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for bool_quetion-0.1.7.2.tar.gz
Algorithm Hash digest
SHA256 884fbab095c1d707909f6f491d88f8bafbd9cc0f5a7a0e357c7152cd92cc6cec
MD5 d024d70a71c52b4e54ca084e52172610
BLAKE2b-256 6fd2c7e04043e78d72e5a501803eddbc4c0c41b06fd18e9da8e48c5552cb53ef

See more details on using hashes here.

File details

Details for the file bool_quetion-0.1.7.2-py3-none-any.whl.

File metadata

  • Download URL: bool_quetion-0.1.7.2-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for bool_quetion-0.1.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1ad6f003de361133aae888280b2bebc83ec65fa062beaaad0c61c362c64ae8e2
MD5 d60381e91c798e0bd74d962175331623
BLAKE2b-256 78149a650f35cc898ee5e4741466f437c28ee14261a8a609ec7b4ff98961dec3

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