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 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.3.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.3-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bool_quetion-0.1.7.3.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.3.tar.gz
Algorithm Hash digest
SHA256 6ed70e1fa2c2fd4108d81467597243c15c814f526926290e76f2bb5e24692259
MD5 ecf76210fd9a139d2069535f5287ce10
BLAKE2b-256 87f9f14849d3937efb42b188e8ba479965d46196f6cae30155e67d043821662a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bool_quetion-0.1.7.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 663f8eb6f2cdd8d3ba26f6f2f7486df530dc44f29cec66ecf056a442659f6fd6
MD5 94b5895f10e2a1603de17e8332a3c502
BLAKE2b-256 f71f06c09f1a6971c7f20631f69ca4b6b5143fa122013c5eec07f0622242d3d3

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