Skip to content

Tag: validation

Dependencies validation using Cerberus

Am validating a CSV file with Cerberus but am struggling with what I’d assume is some basic logic Scenario: A CSV file has 2 columns. Column 2 requires to have a value only if Column 1 has a value. If Column 1 is empty then Column 2 should also be empty. Am thinking this would be one of the most

Asking the user for input until they give a valid response

I am writing a program that accepts user input. The program works as expected as long as the the user enters meaningful data. But it fails if the user enters invalid data: Instead of crashing, I would like the program to ask for the input again. Like this: How do I ask for valid input instead of crashing or a…

How to check if a string is a valid regex in Python?

In Java, I could use the following function to check if a string is a valid regex (source): Is there a Python equivalent of the Pattern.compile() and PatternSyntaxException? If so, what is it? Answer Similar to Java. Use re.error exception: exception re.error Exception raised when a string passed to one of th…