Exception Attributes
OSError.winerror — exception attribute
Inspect a native Windows error number on Windows. It is not a portable attribute: non-Windows OSError objects do not expose it. On Windows an integer winerror constructor argument determines the translated errno. Use getattr(error, "winerror", None) for portable diagnostics and errno for cross-platform branching. This example only simulates construction.
Formal Syntax & Structure
python syntaxpython
error.winerrorReturn Value
int | None (Windows); absent elsewhere
Native Windows code, if supplied on Windows.
Working Example
Example Snippetpython
import syserror = OSError(2, "missing", "input.txt", 2)print(sys.platform == "win32")print(getattr(error, "winerror", None))