Check (Version 2)
A module to check the user input against some requirements.
from PythonFunctions.Check import Check
check = Check()
Usage
- check.getInput(input, type, callback, args)
The main function, Basically every check is called through this
- Parameters
input (str) – The stuff to ask the user
type (check.ModeEnum) – The check to run
callback (function.) – The function to run after the user input. (Must be able to pick up at least 1 argument)
args (any) – Other arguments required for the check
- Returns
Depends on the check
- Return type
any
Everything is called and passed though the above function, however for some of the things to work more arguments are required as well.
ModeEnum
This enum is a variable used for declaring the mode that the getInput function should call when it wants the input. This enum contains all of the possible checks and is required to use.
Int Check (Version 3)
- check.getInput(input, type, *, higher, lower)
The main function, but with all the arguments of an int check
- Parameters
input (str) – The stuff to ask the user
type (check.ModeEnum.int) – The check to run.
higher (int) – Optional, The higher range value
lower (int) – Optional, The lower range value
- Returns
The result of the check (int = passed, none = failed)
- Return type
int | None
Note
If higher or lower aren’t definied it will just check if it is an int value. If one or both are defined, then it will make sure the value is between that range (or smaller / bigger)
from PythonFunctions.Check import Check
check = Check()
result = check.getInput("Please enter a number between 1 and 10: ", check.ModeEnum.int, 1, 10)
print(result)
Yes No Check (Version 2)
- check.getInput(input, type, *, y, n, yA, nA)
The main function, but with arguments for a yes no check
- Parameters
input (str) – The stuff to ask the user
type (check.ModeEnum.yesno) – The check to run.
y (function) – (Optional) The yes return function
n (function) – (Optional) The no return function
yA (any) – (Optional) Data to pass into the yes function
nA (any) – (Optional) Data to pass into the no function
- Returns
If yes or no got entered
- Return type
bool
from PythonFunctions.Check import Check
check = Check()
result = check.getInput("Do you want to continue [Y/n]: ", check.ModeEnum.yesno)
print(result)
from PythonFunctions.Check import Check
check = Check()
def yesFunc():
print("Hello I win")
def noFunc():
print("*Cries* :(")
result = check.getInput("Win game? [Y/n]: ", check.ModeEnum.yesno, y=yesFunc, n=noFunc)
print(result)
Note
If y or n does not exists and that is the function that is meant to be called (e.g. call yesFunc but it doesn’t get passed) Then the value True or False will be returned depending on the context and input. yA and nA will be useless without the function y or n
Note
By default, it will return the result of the function (if it returns), else it will return the result of True
Str Check (Version 1)
- check.getInput(input, type, *, info)
The main function but with arguments for a str check
- Parameters
input (str) – The stuff to ask the user
type (check.ModeEnum.str) – The check to run.
info (tuple | list) – The list to check the value against
- Returns
if input is in info
- Return type
bool
from PythonFunctions.Check import Check
check = Check()
result = check.getInput("Vowel: ", check.ModeEnum.str, info=("a", "e", "i", "o", "u"))
print(result)
Path Check (Version 2)
- check.getInput(input, type)
The main function but with arguments for a path check.
- Parameters
input (str) – The stuff to ask the user
type (check.ModeEnum.path) – The check to run.
info (tuple | list) – The list to check the value against
- Returns
if input is in info
- Return type
bool | string
from PythonFunctions.Check import Check
check = Check()
result = check.getInput("Path: ", check.ModeEnum.path)
print(result)
Note
If “” is passed though, then false will be returned.n If an invalid path is passed in, then the program will ask again.n If a valid path is passed in, the path will be returned.