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
Post a Comment