Check

Last Updated: v1.5

A module to check the user input against some requirements.

from PythonFunctions.Check import Check
check = Check()

Usage

check.getInput(input, type, *, callback, rCheck=False, **info)

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)

  • rCheck (bool) – Returns the input value as well as check result

  • info (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

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, lower=1, higher=10)
print(result)

Yes No Check

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(arg):
    print("Hello I win")
    print(arg)

def noFunc(arg):
    print("*Cries* :(")
    print(arg)

result = check.getInput("Win game? [Y/n]: ", check.ModeEnum.yesno, y=yesFunc, n=noFunc, yA='e', nA='*cries*')
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

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

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.

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

This uses the Save module and that file system structure, Please refer to that method for path information

Location Check (NEW)

check.getInput(input, type, *, x, y):

Converts a message over to a location and checks it.

Parameters
  • input (str) – The stuff to ask the user

  • type (check.ModeEnum.Location) – The check to run

  • X – (Optional), The bigger limit that X can be

  • y (y) – (Optional), The bigger limit that y can be

Returns

If input is in valid range. (Position)

Return type

list[int, int]

Note

This uses the Convert.Location module. Please refer to that method for more information