Answer by Harsh Verma for "or die()" in Python
Ideally, you would want to die/panic with a helpful stack-trace so that you can easily locate the issue.Hence, unlike the most popular answer, you should AVOIDsys.exit() or raise a SystemExit because...
View ArticleAnswer by Duncan for "or die()" in Python
Lot's of good answers, but no-one has yet suggested the obvious way to write this in Python:assert check_something(), "Incorrect data"Just be aware that it won't do the check if you turn on...
View ArticleAnswer by kindall for "or die()" in Python
If you are dealing with an API that you didn't write that returns truthy values on success and falsy values on failure, that seems like a reasonably readable and compact way to do it. If you have...
View ArticleAnswer by cwallenpoole for "or die()" in Python
Well, first, sys.exit([arg]) is more common, and if you really wanted something equivalent to die in PHP, you should use that, raise a SystemExit error, or call os._exit.The major use of the die method...
View ArticleAnswer by Keith Devens for "or die()" in Python
While that style is common in PHP and Perl, it's very un-Pythonic and I'd encourage you not to write Python that way. You should follow the conventions in the language you're using, and write something...
View ArticleAnswer by Ignacio Vazquez-Abrams for "or die()" in Python
The biggest disadvantage is that all dying is now the same. Better to have check_something() raise a more accurate exception and then catch that up above if appropriate.
View ArticleAnswer by user847229 for "or die()" in Python
It seems like you are just wrapping php lingo in python with a one line function. I would advise against it as you might confuse your audience. Exceptions are also a completely different beast than die...
View Article"or die()" in Python
Is anyone using anything like this in Python:def die(error_message): raise Exception(error_message)...check_something() or die('Incorrect data')I think this kind of style is used in PHP and Perl.Do you...
View Article
More Pages to Explore .....