system: win10
IDLE:spyder
script: use try..except to handle exception problems (the output is not consistent with the case result, I don"t know why)
-sharp!/usr/bin/python
-sharp Filename:try_except.py
import sys
try:
s = input("Enter something -->")
-sharp-sharp python3inputraw_input
except EOFError:
print("\nWhy did you do an EOF on me?")
-sharp-sharp \n pyhton
sys.exit() -sharp exit the progarm
except:
print("\nSome error/exception occurred.")
-sharp here,we are not exiting the progarm
print("Done")
then run the actual result of the script
$python try_except.py
Enter something--> (enter directly)
Done (get Done)
results in the tutorial
$python try_except.py
Enter something-->
Why did you do an EOF on me?
that is, there is no EOFrror exception in the block of try, and Done is output. What is the reason for this? How can I solve this problem?