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:

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.5.tar.gz (15.4 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.5-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bool_quetion-0.1.7.5.tar.gz
  • Upload date:
  • Size: 15.4 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.5.tar.gz
Algorithm Hash digest
SHA256 8bba6f474a8b1ecda4bf1e886c43ab5f9ad85ce042c8906b10a5c44dd58f5151
MD5 402d3e4fa8651bf144b81c25eac0ae3e
BLAKE2b-256 08e9a2c2fdda777af3ef2792f873e534f2586469b696911d4c7fe02dc6add4eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bool_quetion-0.1.7.5-py3-none-any.whl
  • Upload date:
  • Size: 15.8 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9bb7900a766e6abe9151be8093fc3891fee7d6891aeb7969205a9e4ac26d30c6
MD5 3cc5cacd3d5264c6b723fb5573b665ea
BLAKE2b-256 f79babefaaf91019271cd1704d09347b329c5cb7691cefbfbf5c4ca544b117fb

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