A simple helper function for reading integers and floats from input
Project description
IntputLib
Because typing int(input()) everywhere is a rite of passage we'd rather skip.
⚠️ Disclaimer: This started as a joke among friends after someone accidentally typed intput. Don't take it too seriously.
What is this?
IntputLib is a tiny Python library designed to save you from the repetitive strain of capturing numerical input from users. It handles the boring try-except loops so you can focus on the fun parts of your code.
No more writing this masterpiece of error-handling over and over again:
while True:
try:
x = int(input("Enter a number: "))
break
except ValueError:
print("Invalid input. Please enter a number.")
Installation
Just a simple pip install away (if only everything in life were this easy):
pip install intputlib
Usage
Here’s how you can reclaim your time and sanity.
Basic Integer Input
Use intput() as a smarter, more patient version of int(input()).
from intputlib import intput
age = intput("Enter your age (or fake it, we won't judge): ")
print(f"You are {age} years old!")
Integer Input with a Custom Error Message
Tired of the generic "invalid input"? Give your users a custom message.
from intputlib import intput
score = intput("Enter your score: ", error_msg="Come on, numbers only!")
print(f"Your score: {score}")
Integer Input within a Range
Keep your users in line by specifying a minimum and maximum value.
from intputlib import intput_range
level = intput_range("Choose a level (1-10): ", min_val=1, max_val=10)
print(f"You selected level {level}!")
Custom Error Message for Range Input
You can also customize the error message for out-of-range inputs.
difficulty = intput_range(
"Select difficulty (1-5): ",
min_val=1,
max_val=5,
error_msg="Oops! Only numbers between 1 and 5 are allowed."
)
print(f"Difficulty set to {difficulty}")
Basic Float Input
For when you need those decimal points.
from intputlib import floatput
height = floatput("Enter your height in meters (e.g., 1.75): ")
print(f"Your height: {height} m")
Features
- Simplified Input: Read integers and floats with a single, clean function call.
- Hassle-Free Validation: Automatically handles
ValueErrorand keeps asking until a valid number is entered. - Range Enforcement: Easily restrict integer inputs to a specified range.
- Customizable Prompts: Tailor your input prompts and error messages.
- No More Crashes: Saves your scripts from the dreaded
ValueErrorwhen a user types "abc" instead of "123".
Why Use This?
Because life is too short to write the same validation loop for the hundredth time. Let intput() handle the nagging for you, so you can get back to building amazing things.
License
MIT License. Because sharing is caring.
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 intputlib-1.1.4.tar.gz.
File metadata
- Download URL: intputlib-1.1.4.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15863004ef58636914c105f937edcca55e9cec2e24c8aa308eb67285282b43ca
|
|
| MD5 |
eae741f693c21f2a7b55d51eebfa1fff
|
|
| BLAKE2b-256 |
e10d2821cf21b8840280a58c50034acacfb164991bbaeabcfee63ece0bf66fee
|
File details
Details for the file intputlib-1.1.4-py3-none-any.whl.
File metadata
- Download URL: intputlib-1.1.4-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3510224931b5492927123128c7cd49830835fa8e7df92bd380cefff7e685ea45
|
|
| MD5 |
5ebbd8c4bf971d6c8ab72d2018266afe
|
|
| BLAKE2b-256 |
69cffc65cac6ed0084afbd5dac06dff6acc900a094a26434a343bd2b6a2e9478
|