Skip to main content

A simple helper function for reading integers and floats from input

Project description

IntputLib

PyPI

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 ValueError and 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 ValueError when 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

intputlib-1.1.3.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

intputlib-1.1.3-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file intputlib-1.1.3.tar.gz.

File metadata

  • Download URL: intputlib-1.1.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for intputlib-1.1.3.tar.gz
Algorithm Hash digest
SHA256 5e8e1c6e6f5fb2f5c7fb580855a201d1a8b09dc2ef29c27537ad99e583cff06a
MD5 6d9e18b81e8cc53735ec7083eb331f7b
BLAKE2b-256 9cf1d02d02bd4f8a3fd0e03b81441977023ff87033b092a84028c826c4614ae4

See more details on using hashes here.

File details

Details for the file intputlib-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: intputlib-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for intputlib-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0aa7bbb7ac83a721dcbeda2e8b48a06c8d564327a093149145b653c349dc0c04
MD5 b1bfac2a141f0d4db44ca9df09bb0ab1
BLAKE2b-256 4fcd0e71f1c199a9d063828f3c6d2cb5d5b9d35091b811bec4a2e2ddbbbad38e

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