Validation - Augustin007/usefulpy GitHub Wiki
The validation section is mostly about validating input and output.
Note: it imports functions from collections and random, and imports datetime as a whole.
Functions of usefulpy.validation:
YesOrNo(Response)
Check if a text is an affirmative or a negative
centerbias(low, high)
return a random integer from low to high, center numbers have higher weights
falsebias(chance=75)
return a random boolean value, biased to False, or a chance% to return False
floatinput(Prompt='', beginning='', ending=None, Chastisement='\nYour input was invalid.\nPlease try again\n')
Continue to repeat an input prompt until the prompt can be converted into a float.
floatlistinput(Prompt='', beginning='', ending=None, Chastisement='\nYour input was invalid.\nPlease try again\n')
Continue to repeat an input prompt until the prompt can be converted into a list of floats.
fromrepr(s: str)
not perfect, but it is supposed to be the inverse of repr(x)=s
getYesOrNo(Prompt='', beginning='', ending=None, Chastisement='\nYour input was invalid.\nPlease try again\n')
Continue to repeat an input prompt until the prompt can be converted into a boolean value, this includes variations of Yes and No.
highbias(low, high)
return a random integer from low to high, higher numbers have higher weights
intinput(Prompt='', beginning='', ending=None, Chastisement='\nYour input was invalid.\nPlease try again\n')
Continue to repeat an input prompt until the prompt can be converted into an integer.
intlistinput(Prompt='', beginning='', ending=None, Chastisement='\nYour input was invalid.\nPlease try again\n')
Continue to repeat an input prompt until the input can be converted into a list of integers
is_float(s)
Check if an object can be turned into a float
is_floatlist(s)
Check if a list is composed solely of numbers
is_function(s)
Check whether variable s is a function
is_integer(s)
Check if an object can be turned into an integer without losing any value
is_intlist(s)
Check if a list is composed solely of integers
isbool(s)
Check if s is a boolean value
lowbias(low, high)
return a random integer from low to high, lower numbers have higher weights
makelist(*s)
Makes a list out of nearly any input of any type
outerbias(low, high)
return a random number from low to high, outermost numbers have higher weights
rbool()
return a random boolean value
rnum = random() method of random.Random instance
random() -> x in the interval [0, 1).
truebias(chance=75)
return a random boolean value, biased to True,or a chance% to return True
tryfloat lambda s
tryint(s)
Try to turn an object into an integer
trynumber lambda s
trytype(ntype, *s)
Try to convert data s into a type ntype
validdate(year, month, day)
Check if a year, month, day combo is valid
validinput(validquery, *Prompt, returnclass=<class 'str'>, numinputs=None, beginning='', ending=None, Chastisement='\nYour input was invalid.\nPlease try again\n', ninput=None)
Continue to repeat an input prompt until the prompt is validated by validquery
validquery(ntype, *s)
Check if s can be converted into a type ntype