eoferror eof when reading a line – Handling EOFError Exception in Python

Rate this post

eoferror eof when reading a line – What is EOFError? – EOFError is raised when one of the built-in Python functions input() as well as raw_input() hits an end-of-file condition (EOF) without reading any data.

[Solved] EOFError: eoferror eof when reading a line

As per the Python documentation Python input raises an EOFError when it hits an end-of-file main condition.

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

This Python exception can be handled as:

Read Also:  glob images - Php list all images in folder and subfolders

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

How to tackle EOFError?

try:
    input("Please enter something")
except:
    print("EOF")

https://docs.python.org/3.5/library/exceptions.html

Free Live Chat for Any Issue

How to remove EOFError: EOF when reading a line?

def process_input():
    p = input()
    while True:
        try:
            dt = input()
        except EOFError:
            return
        res = dt.find(p)             
        if res != -1:
            print(dt)
        if dt=='':
            return

Download

I hope you get an idea about eoferror eof when reading a line.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.