python equivalent to java guava Preconditions -


does python have equivalent java preconditions library. e.g.

in java, can check parameters this:

public void dummymethod(cat a, dog b) {    preconditions.checknotnull(a, "a can not null.");    preconditions.checknotnull(b, "b can not null.");    /**    logic    **/    } 

if or b null, java throws runtime exception, how python, what's best practice here python?

while can use assert verify conditions, best practice in python document behaviour of function, , let fail if preconditions not met.

for example, if reading file, like:

def read_from_file(filename):     f = open(filename, 'ru') # allow ioerror if file doesn't exist / invalid permissions 

rather testing failure cases first.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -