Python EOFError Exception
Example
An EOFError occurs if input() reaches the end of the input, before any text is read:
x = input()
Try it Yourself »
Definition and Usage
The EOFError exception occurs when the input() function reaches the end of the input (EOF, End Of File) without reading any text.
This can happen when a program gets its input from a file or from another program, and there is no more input. It also happens in online editors that do not send any input to the program.
Exception Handling
Example
Handling the EOFError in a try...except statement:
try:
x = input()
except EOFError:
print("No input was given")
Try it Yourself »
Related Pages
Read more about handling errors in our Python Try Except Tutorial.