Skip to content

EOFError

In Python, EOFError is a built-in exception that occurs when the built-in input() function hits an end-of-file (EOF) condition without reading any data. This typically occurs when you’re trying to read input from a source that has no more data to provide.

As a developer, you’ll most often encounter this exception when reading interactive input with input() and the user signals end-of-file (for example, by pressing Ctrl+D on Unix or Ctrl+Z on Windows), or when piped standard input runs out before input() returns. File methods like io.TextIOBase.read() and io.IOBase.readline() don’t raise EOFError. They return an empty string at EOF instead.

EOFError Occurs When

The built-in input() function hits an end-of-file (EOF) condition without reading any data.

EOFError Can Be Used When

  • Handling unexpected EOF conditions when reading input from a user
  • Catching EOFError from functions that signal EOF by raising rather than returning, such as pickle.load() or marshal.load() on a truncated stream
  • Designing interactive scripts that can handle EOF conditions gracefully without crashing

Tutorial

How to Read User Input From the Keyboard in Python

Reading user input from the keyboard is a valuable skill for a Python programmer, and you can create interactive and advanced programs that run on the terminal. In this tutorial, you'll learn how to create robust user input programs, integrating error handling and multiple entries.

basics best-practices

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated May 11, 2026