How to remove EOFError: EOF when reading a line?

Nothing is overlooked. As per the documentation input raises an EOFError when it hits an end-of-file condition. Essentially, input lets you know we are done here there is nothing more to read. You should await for this exception and when you get it just return from your function or terminate the program.

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

Leave a Comment