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
Using a virtual environment.
Create virtual environment:
python3 -m venv .venv
Activate virtual environment:
source .venv/bin/activate
Install bool_quetion:
pip install bool_quetion
If you're not using a virtual environment and want to install packages globally, you'll likely need --break-system-packages to bypass restrictions that protect system:
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 python3-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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bool_quetion-0.1.8.tar.gz.
File metadata
- Download URL: bool_quetion-0.1.8.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a36a0ff5c1371a8ab988a256fb0cdb39b2479ac3d21a83679b17c16486b08449
|
|
| MD5 |
1587a2b5f76e5554e2a46c895c255797
|
|
| BLAKE2b-256 |
d64d4fc0d2602190cd366f43bae50960cd6f3d36dae6802191bc485f55a306de
|
File details
Details for the file bool_quetion-0.1.8-py3-none-any.whl.
File metadata
- Download URL: bool_quetion-0.1.8-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7766d6f70e7d07542b48f099c04eee11fcbe75cb6259495c3d47a9fcb4b0099f
|
|
| MD5 |
1b65c67b19015aad69022481b69a137b
|
|
| BLAKE2b-256 |
9d74a3361688c9eb47baa29591c3425635fdc474f04e08b6848701f9573de35f
|