I am aware of some facts about sys.exit()
. However, I have seen some usage of sys.exit(_("some error msg blablabla"))
, is there any differences between them?
Asked
Active
Viewed 214 times
-1

shwsun
- 27
- 4
-
3*Where* have you seen that? Is in in something using `_` for i18n (see http://stackoverflow.com/a/5893946/3001761, #2)? Have you read https://docs.python.org/3/library/sys.html#sys.exit? – jonrsharpe Dec 07 '16 at 23:58
-
I have read the official doc, the stackoverflow post is useful, thx. – shwsun Dec 09 '16 at 01:02
1 Answers
0
One would be use to exit out and display a message on the console, so if you are for example running a game and let's say you have a menu:
Option 1 - Play Option 2 - Options Option 3 - Exit
If the user selects option 3 you could then call sys.exit() but what if you wanted to show a nice message to engage them say sys.exit('Thank you for playing I hope you come back soon') basically that will be displayed after the player selects option 3.

Dilmer
- 169
- 8
-
If you pass a string (or anything other than an `int` or `None`), then `sys.exit` will set the system exit status to 1 (failure). So you wouldn't use it to show “a nice message”, but you could use it to display an error message explaining why you're exiting the program. – dan04 Dec 08 '16 at 00:23
-
if you pass the value of 0 which is an integer then is considered “successful termination” so you can show a nice message, and yes anything other than that will be a failure. – Dilmer Dec 08 '16 at 00:40