Exception Attributes
OSError.filename — exception attribute
Read the first path associated with an OS exception, when available. The path is the original input rather than a guaranteed canonical or absolute path. It may be bytes or another path representation; do not expose sensitive paths in public logs.
Formal Syntax & Structure
python syntaxpython
error.filenameReturn Value
object | None
First path associated with the failure.
Working Example
Example Snippetpython
import errnoerror = OSError(errno.ENOENT, "missing input", "input.txt", None, "output.txt")print(error.filename)