all Python 3Exceptionsexception
EOFError
built-in exceptions
input() hit end-of-file (EOF) without reading any data.
Syntax
raise EOFError
On judge systems this is the normal "input ran out" signal when stdin comes from a file or a pipe rather than a keyboard: a while True: s = input() loop eventually hits the end of the stream. Note that only input() raises it — lower-level reads behave differently, since sys.stdin.readline() and file.read() simply return an empty string at EOF. So either catch EOFError to break the loop, or iterate with for line in sys.stdin, where the end of input is handled for you.
Examples
try:
raise EOFError
except EOFError as e:
print(type(e).__name__) # → EOFError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy