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 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

As root or using sudo

Add APT repositories:

echo "deb https://pablinet.github.io/apt ./" > /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:

apt update

Install bool_quetion:

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: bool_quetion-0.1.7.4.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.4.tar.gz
Algorithm Hash digest
SHA256 91e935d79c769ceff22954db111afa6daf91ae3dbd62d7b1fa5d831238009f95
MD5 885d40da3fe2c0a35ca3c2ce5be660b5
BLAKE2b-256 327fd8a09137308f65550aac7acb8f4c722b2dabbce194f94c4aebb2871eefdb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bool_quetion-0.1.7.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 88fb062bb1bbbddb94dfcfb6abfe3a686ba37388136e5c547dc28daedc99b208
MD5 d516c56435c4e9d6452be9fc0b714e4c
BLAKE2b-256 4a7269b04944f984ef39dad302cc9d9da5467005e598a4be5491fedfeb2d802b

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