I am running the following code (example from the book "Python: Automate the Boring Stuff" by Al Sweigart):
import sys
while True:
print('Type exit to exit')
response = input()
if response == 'exit':
sys.exit()
print('You typed ' + response + '.')
When the program in run with PyCharm, if the response is "exit", the program finishes with message "Process finished with exit code 0". Which, if I understand it correctly, means that the program worked as expected and there were no error.
However, if the code is executed in mu editor (recommended in the book to be used)
Traceback (most recent call last):
File "c:\users\nelly\mu_code\chapter2.py", line 7, in <module>
sys.exit()
SystemExit
>>>
---------- FINISHED ----------
exit code: 2 status: 0
As far as I understand, it means that program didn't finish its work as expected in normal mode. Why the exit code is different? Is it a normal message for mu editor in this case? Do I need to change the settings of the mu editor?
I encountered the same issue - sys.exit() on MU (or on repl.it for that matter) will cause a traceback. My understanding is that the error is a result of MU being a REPL and not an IDE. If you run your program with the terminal or any IDE configured to run Python, it'll exit properly. Interesting note as I'm delving deeper into Python, the sys.exit() raises the System Exit exception. So my guess is that MU catches that exception since there's nothing to really "exit" to.