-1

I've been using Python more and more recently, and I'd like to know if Python scripts need an exit statement at the end? If they don't is it proper to always add an exit statement at the end of a script?

Jonathan
  • 3
  • 3
  • See [this thread](http://stackoverflow.com/questions/19747371/python-exit-commands-why-so-many-and-when-should-each-be-used) on system exiting. – nbryans Jun 22 '16 at 21:00

3 Answers3

1

No, python scripts do not need an exit- in fact, a raw quit() or exit() at the end of many things may break them - in the case of importing something, all top-level code is executed: if that contains an exit(), the whole importing program will exit, which is almost certainly not desired.

If in doubt, Python will almost always clean up after itself (zombie threads may be an exception, but that's way more advanced).

Delioth
  • 1,564
  • 10
  • 16
0

You do not need an exit statement in Python code, unless you want to set the exit code yourself

3Doubloons
  • 2,088
  • 14
  • 26
0

This is unnecessary. There is no such thing as an "exit statement" in Python, and calling a function like sys.exit() at the end of your program does the same thing as just letting execution flow off the end of your program.

user2357112
  • 260,549
  • 28
  • 431
  • 505