Errno Module

Indices and tables

Introduction

It can be quite useful to have a standardized error number as part of an exception, or as the return value from your function or application. The errno module compliments this goal.

Error Codes

The errno module defines over 100 constants to describe various erroneous situations. For example

Error Mapping

There are two types of mapping with error values that can be performed:

  • Using the errno.errorcode dictionary, you can go from error number, to the name of the constant that is defined for it. For example:

    >>> import errno
    >>> errno.errorcode[1]
    'EPERM'
    
  • Using os.strerror(), you can go from error constant, to a string error message. For example:

    >>> import errno
    >>> import os
    >>> os.strerror(errno.EPERM)
    'Operation not permitted'