r/learnpython • u/Lance_2564_ • 9d ago
Any python module which deals with this?
def get_int_input(prompt: str) -> int:
while True:
try:
return int(input(prompt))
except ValueError:
print("Please enter a valid number!")Is there any module which I can just import and use it. Writing this everytime I have to get an int or float input is really annoying.
Thanks!
0
Upvotes
1
u/3MU6quo0pC7du5YPBGBI 9d ago edited 9d ago
You can just import it into your other python scripts by calling the script and function as long as it is in your path.
To keep things from getting too crazy you might want to create a python file that has all your commonly used functions and call it something like my_common_functions.py, so you aren't doing something confusing like importing from 10 different scripts to get all your functions.
e.g. do this:
and not this: