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)   # True

Related terms

Taught in

References

Certification courses