The exit and quit "functions" are actually site.Quitter objects and are loaded, at interpreter start up, from site.py. However, if the interpreter is started with the -S flag, or a custom site.py is used then exit and quit may not be present.

Replace uses of exit() and quit() with sys.exit() which is built into the interpreter and is guaranteed to be present.

In this example, exit() is used and will fail if the interpreter is passed the -S option.

In this example, sys.exit() is used and will behave the same regardless of the interpreter options.

  • Python Documentation: Command line and environment.
  • Python Documentation: Site-specific configuration hook.