all Python 3osfunction
os.strerror
os — system
Return the text message for an errno error code.
Syntax
os.strerror(code)
For an unknown error code Linux and macOS do not raise but return a string like 'Unknown error 99999'; on platforms where the C strerror returns NULL, ValueError is raised. The text depends on the system and its locale, so never compare messages in code — compare numbers via the errno module. An OSError already carries the same description in its strerror attribute.
Examples
import os
import errno
print(os.strerror(2)) # → No such file or directory
print(os.strerror(errno.EACCES)) # → Permission denied
print(OSError(2, os.strerror(2), 'data.csv')) # → [Errno 2] No such file or directory: 'data.csv'
print(os.strerror(9999)) # → текст для неизвестного кода зависит от ОС, например Unknown error 9999 (на части платформ — ValueError)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy