sys.exit() not working in python repl?
richardnicholas

Hi all, I am not sure if this is a problem with repl.it or I am just coding the python wrong. My simple code to open a file is:

try:
file_in = open ('data_file', 'r')
except:
print ("Could not open data_file for reading.")
sys.exit(1)
print ("Why doesn't this exit work?")

All is well if data_file exists but if not, we go to the except where it does a print and should exit. But the program hangs there until I press Stop. The 2nd print statement does not occur either so it looks like it goes into exit() but does not come out?

Ideas? Thanks.

Edit to original question: I see the whitespace indentation got lost when I submitted the question but it is correct in the real code.

You are viewing a single comment. View All
UnikaftUnikaft

@multicoder2021 i think what he means is that when the code runs exit() it says "repl process died unexpectedly: >"
i'm having the same problem.