For the \"q\" (quit) option in my program menu, I have the following code:
elif choice == \"q\":
print()
That worked all right until I
The actual way to end a program, is to call
raise SystemExit
It's what sys.exit does, anyway.
A plain SystemExit, or with None as a single argument, sets the process' exit code to zero. Any non-integer exception value (raise SystemExit("some message")) prints the exception value to sys.stderr and sets the exit code to 1. An integer value sets the process' exit code to the value:
$ python -c "raise SystemExit(4)"; echo $?
4