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
EOFErrorfrom functions that signal EOF by raising rather than returning, such aspickle.load()ormarshal.load()on a truncated stream - Designing interactive scripts that can handle EOF conditions gracefully without crashing
Related Resources
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.
For additional information on related topics, take a look at the following resources:
- Python's Built-in Exceptions: A Walkthrough With Examples (Tutorial)
- Python Exceptions: An Introduction (Tutorial)
- Python's raise: Effectively Raising Exceptions in Your Code (Tutorial)
- Reading User Input From the Keyboard With Python (Course)
- Working With Python's Built-in Exceptions (Course)
- Python's Built-in Exceptions: A Walkthrough With Examples (Quiz)
- Introduction to Python Exceptions (Course)
- Raising and Handling Python Exceptions (Course)
- Python Exceptions: An Introduction (Quiz)
- Using raise for Effective Exceptions (Course)
- Python's raise: Effectively Raising Exceptions in Your Code (Quiz)
By Leodanis Pozo Ramos • Updated May 11, 2026