Since you are discussing return
here, it seems that you can program Python, for example C. Most Python functions should ideally be written to throw an exception if they fail, and the calling code can determine how to handle the exceptional conditions. For validation functions, it is best to return True
or False
- not as literals, usually, but as the result of some expression like s.isdigit()
.
Speaking about the return value of a process in its environment, you can use return
, because the module is not a function, so the return
at the top level will be marked as a syntax error. You should use sys.exit
instead.
Python may seem a bit minimalistic in this regard, but calling sys.exit
with no default arguments for success (i.e. return code 0). Thus, the easiest way to simplify your program may be to stop its encoding with an argument in which you do not want to indicate a failure!
As the documentation reminds us, integer arguments are passed back, and string arguments lead to return code 1
, and the string is printed on stderr
.
As far as I know, the language does not contain any constants (although it has functions specific to some environments, if it provided exit codes, their values ββmay be required for implementation or for the platform, and the language developers prefer to avoid this whenever possible .
source share