inputwhile
A simple but helpful package that allows you to create input while loops with different conditions.
Explanation nobody cares about
Once, I was tired of writing:
value = input()
while not condition(value):
value = input()
every time I wanted to check if a user entered the right value in a program.
So, I decided to make this package (my first one). It has a bunch of functions with pre-defined condition functions, but you can make custom inputwhiles too.
Installation
# Linux/macOS
python3 -m pip install inputwhile
# Windows
py -3 -m pip install inputwhile
Quick examples
Custom error messages
import inputwhile
# If input value is an empty string it will print "Enter your username:" again until input value is not empty
string = inputwhile.stringNotEmpty(
"Enter your username:"
)
# If input value is an empty string it will print "You can't leave it empty. Please enter your username:" until input value is not empty.
string = inputwhile.stringNotEmpty(
"Enter your username:",
error_prompt="You can't leave it empty. Please enter your username:"
)
# error_prompt is optional, but is also in all package functions.
Number inputwhiles
import inputwhile
integer = inputwhile.integer(
"Enter a number:",
error_prompt="Invalid number. Please enter a valid number:"
)
floatNumber = inputwhile.floatInput(
"Enter a float:",
min=0.0,
max=1.0 # You can add ranges too.
)
Custom types
import inputwhile
from myproject import BigInt
# Will request a value until it is parsable like: BigInt(value) and will return it with that type.
value = inputwhile.customTypeClass(
"Enter the nuclear code:",
typeClass=BigInt
)
Boolean inputwhiles
import inputwhile
# Only matches "true" or "false"
boolean = inputwhile.boolean(
"It is illegal to keep a guinea pig in Switzerland. True or false?:",
"Prompt not recognized. Please enter 'true' or 'false':"
)
# Matches "true", "t", "yes", "y", "1", "si", "sí", "s" or "false", "f", "no", "n", "0", "nope" by default.
flexibleBoolean = inputwhile.booleanFlexible(
"Do you want to continue? (y/n):",
trueStrings={"continue"},
falseStrings={"exit"},
doUseCustomNDefaults=True # Makes trueStrings and falseStrings being added to the default ones instead of replacing them.
)
regexBoolean = inputwhile.booleanFlexibleRegex(
"Do you like tacos?:",
trueRegex=f"^(yes|true|you don't have an idea|definitely|yes,[\s]*[\w]+)$"
falseRegex=f"^(no|definitely no|never|no,[\s]*[\w]+)$"
error_prompt="Prompt not recognized. Try again:"
)
Lists
import inputwhile
# List of strings
stringsList = inputwhile.listInput(
"Enter the countries you have ever visited:",
separator=",",
error_prompt="Please, don't leave empty the input:",
doStriptElements=True # Makes a element.strip() to every element in the list
)
# Can filter the list
from pathlib import Path
filteredList = inputwhile.listInput(
"Enter the directories you want to scan:",
separator=" ",
error_prompt="Invalid directories. Please enter at least one directory:"
filter_func=lambda x: Path(x).is_dir()
)
# Can map too
mappedList = inputwhile.listInput(
"Enter the values of the Mexican peso per day in the last month:"
error_prompt="Enter at least one value:"
map_func=lambda x: int(x),
filter_func=lambda x: inputwhile.utils.isParsable(x, int)
)
# Also sets available for unique values
setsToo = setInput(
"Enter your social media urls:",
separator=" ",
error_prompt="Enter at least one url:"
filter_func=lambda x: x.startswith("http")
)
# And of course regex
regexList = inputwhile.listRegex(
"Enter your hobbies separated by commas:",
regex_separator=r"[,]+",
doStripElements=True
)
regexSet = inputwhile.setRegex(
"Enter the file extensions you like the most:"
regex_separator=r"[.,\s]+"
)
Links
Metadata
Release files for inputwhile 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| inputwhile-1.1.2.tar.gz | 6.2 kB | Without provenance | Details for inputwhile-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| inputwhile-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for inputwhile-1.1.2-py3-none-any.whl |
Total release size: 13.8 kB
Release files / inputwhile-1.1.2.tar.gz
| Download URL | inputwhile-1.1.2.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17212a21fa4cb82227583a770201eab61b5d2afc423332d59aa1ec7bc864d56d
|
|
BLAKE2b-256 checksum How to use checksums |
f794c1c653bc2f74a826ecb28c75444f9d2c4088effef6c2acbaa3487b341f40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.5 {"installer":{"name":"uv","version":"0.11.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / inputwhile-1.1.2-py3-none-any.whl
| Download URL | inputwhile-1.1.2-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d44bbea9509c05665f5db8f4ca16547963ca2590b878b1dca117ef69c2dc353
|
|
BLAKE2b-256 checksum How to use checksums |
4ce6c5031364f1037009c693beab5377e734bb374be9c60994baa5835857b7b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.5 {"installer":{"name":"uv","version":"0.11.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for inputwhile 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.