Skip to content
Related Articles

Related Articles

Handling EOFError Exception in Python
  • Last Updated : 02 Sep, 2020

EOFError is raised when one of the built-in functions input() or raw_input() hits an end-of-file condition (EOF) without reading any data. This error is sometimes experienced while using online IDEs. This occurs when we have asked the user for input but have not provided any input in the input box. We can overcome this issue by using try and except keywords in Python. This is called as Exception Handling.

Example: This code will generate an EOFError when there is no input given to the online IDE.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

n = int(input())
print(n * 10)

chevron_right


Output:

This exception can be handled as:



Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

try:
    n = int(input())
    print(n * 10)
    
except EOFError as e:
    print(e)

chevron_right


Output:

EOF when reading a line

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :