Skip to content

Instantly share code, notes, and snippets.

@roskakori
Last active February 5, 2024 19:50
Show Gist options
  • Save roskakori/4572921 to your computer and use it in GitHub Desktop.
Save roskakori/4572921 to your computer and use it in GitHub Desktop.
Python OS error codes with symbolic name and human readable error message
# Print a list of possible Python OS error codes together with the symbolic
# name in `errno` and the related human readable error message. The output
# uses Trac Wiki syntax so it can be copied and pasted in a Wiki document
# for later reference.
#
# The output depends on platform and language settings.
import errno
import os
print('||=code =||=symbol =||=message =||')
for number in sorted(errno.errorcode.keys()):
symbol = errno.errorcode[number]
message = os.strerror(number)
print('||%d||%s||%s||' % (number, symbol, message))
@tiptonnet
Copy link

||=code =||=symbol =||=message =||
Traceback (most recent call last):
File "", line 655, in
File "", line 292, in GetErrorCode
AttributeError: 'module' object has no attribute 'strerror'

@roskakori
Copy link
Author

@tiptonnet Concerning your error:

AttributeError: 'module' object has no attribute 'strerror'

The code still works fine with Python 3.11, and strerror is still part of the standard os package. It seems you are importing some other module under the name os.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment