Skip to content

Instantly share code, notes, and snippets.

View gustavoeso's full-sized avatar
:shipit:
focused

Gustavo Oliveira gustavoeso

:shipit:
focused
View GitHub Profile
def valid_input (validator=str, prompt="", accept=None, reject=[], persist=True, apply=None):
while True:
try:
response = validator(input(prompt))
normalized = apply(response) if apply != None else response
except ValueError:
if persist != False:
print("Invalid input!")
else:
return None