Apologies if this is the wrong way to ask this question.
So I did some basic google searches and looked at the PEP-8 recommendations, but I still can't find a good code guide for my question:
Is it better to exit my python script from within a function or to return 1
and let the __main__
body handle exiting?
Example:
def exit_fun():
if foo:
keep going
else:
exit(1)
if __name__ == "__main__":
exit_fun()
next_fun()
-or-
def exit_fun():
if foo:
keep going
else:
return 1
if __name__ == "__main__":
funfun = exit_fun()
if funfun == 1:
exit(1)
next_fun()
The frist way looks cleaner to my eyes but my eyes don't compare to a style guide.