errno
The error number an OSError carries, and the standard module that names those numbers.
In more detail
When a file operation fails, the OSError subclass raised carries its error number in err.errno. The errno module gives the numbers names: ENOENT for no such file, EACCES for permission denied, EISDIR for a directory, EEXIST for a file that already exists. Compare against these names, because the raw numbers differ between systems.
Example
import errno
try:
open('missing.txt')
except OSError as err:
print(err.errno == errno.ENOENT) # TrueRelated terms
- FileNotFoundError — The exception raised when a program tries to open a file that does not exist at the given path.
- exception — An error object a program raises to stop normal flow and report that something went wrong.
- open() — The built-in function that opens a file by name and returns a file object, for reading by default or for writing or appending.
Taught in
- Streams, Handles And Open Modes — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- read, readline, errno And bytearray — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comprehensions, Closures And Files Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep