Reading online some programmers use sys.exit
, others use SystemExit
.
Sorry for the basic question:
Example
ref = osgeo.ogr.Open(reference) if ref is None: raise SystemExit('Unable to open %s' % reference)
or
ref = osgeo.ogr.Open(reference) if ref is None: print('Unable to open %s' % reference) sys.exit(-1)
The functions* quit(), exit(), and sys. exit() function in the same way: they raise the SystemExit exception. So there is no real difference, except that sys. exit() is always available but exit() and quit() are only available if the site module is imported.
exit([arg]) using Python. Unlike quit() and exit(), sys. exit() is considered good to be used in production code for the sys module is always available.
exit() function allows the developer to exit from Python. The exit function takes an optional argument, typically an integer, that gives an exit status. Zero is considered a “successful termination”.
You usually want to use sys. exit either to conditionally end your script somewhere in the middle of it (when it would be complicated to simply change the execution flow) or to return a different exit code.
No practical difference, but there's another difference in your example code - print
goes to standard out, but the exception text goes to standard error (which is probably what you want).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With