Pyhton encountered Enter something--> "enter directly without content" when handling errors using try..except, resulting in no error.

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?

Apr.02,2022

Concise Python the exception chapter in the tutorial says that EOF is added only when ctrl + d . The code is as follows

.

Code

try:
    text = input('Enter something --> ')
except EOFError:
    print('Why did you do an EOF on me?')
except KeyboardInterrupt:
    print('You cancelled the operation.')
else:
    print('You entered {}'.format(text))

execution result

-sharp Press ctrl + d
$ python exceptions_handle.py
Enter something --> Why did you do an EOF on me?

-sharp Press ctrl + c
$ python exceptions_handle.py
Enter something --> ^CYou cancelled the operation.

$ python exceptions_handle.py
Enter something --> No exceptions
You entered No exceptions

exception concise Python tutorial

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4c9b3-44ec6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4c9b3-44ec6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?