styles - Python Return Codes -


so lately i've been asking few questions more professional , pythonic style in python, , despite being given great answers questions, feel need ask broader question.

in general, when writing utility functions (for library, etc.) deal more side effects (file writes, dictionary definitions, etc.) return values, it's useful return status code tell calling function passed or failed.

in python, there seem 3 ways flag this:

using return value of -1 or 0 (c like) , using statements such as

if my_function(args) < 0:     fail condition pass condition 

or using return value of true/false

if not my_function(args):      fail condition pass condition 

or using 'return or 'return none' using exceptions (exits on unknown error)

try:     my_function(args) except expectedorknownexceptionorerror:     fail condition pass condition 

which of these best? correct? preferred? understand work, , there isn't technical advantage of 1 on other (except perhaps overhead of exception handling).

don't return indicate error. throw exception. don't catch exception , turn return code.


Comments