Welcome, guest | Sign In | My Account | Store | Cart

This recipe is a simple Python introspection utility that displays the defined OS error codes and messages (that Python knows about) from the os.errno module. It works for both Python 2 and Python 3. For each kind of OS error defined in Python, it will display a serial number, the error code, and the corresponding error name, and English error message. E.g. the first few lines of its output are shown below:

$ py -2 os_errno_info.py

Showing error codes and names

from the os.errno module:

Python sys.version: 2.7.12

Number of error codes: 86

Idx Code Name Message

0 1 EPERM Operation not permitted

1 2 ENOENT No such file or directory

2 3 ESRCH No such process

3 4 EINTR Interrupted function call

4 5 EIO Input/output error

More information, full output and other details are available here:

https://jugad2.blogspot.in/2017/03/show-error-numbers-and-codes-from.html

Python, 30 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from __future__ import print_function
'''
os_errno_info.py
To show the error codes and 
names from the os.errno module.
Author: Vasudev Ram
Copyright 2017 Vasudev Ram
Web site: https://vasudevram.github.io
Blog: https://jugad2.blogspot.com
Product store: https://gumroad.com/vasudevram
'''

import sys
import os

def main():
    
    print("Showing error codes and names\nfrom the os.errno module:")
    print("Python sys.version:", sys.version[:6])
    print("Number of error codes:", len(os.errno.errorcode))
    print("{0:>4}{1:>8}   {2:<20}    {3:<}".format(\
        "Idx", "Code", "Name", "Message"))
    for idx, key in enumerate(sorted(os.errno.errorcode)):
        print("{0:>4}{1:>8}   {2:<20}    {3:<}".format(\
            idx, key, os.errno.errorcode[key], os.strerror(key)))

if __name__ == '__main__':
    main()

Output of run

More information and full output and other details available here:

https://jugad2.blogspot.in/2017/03/show-error-numbers-and-codes-from.html