Exception Attributes
SyntaxError.filename — exception attribute
Identify the source name reported by the parser. With compile(), the caller supplies this label; it need not be a real file path. A manually created SyntaxError may omit it.
Formal Syntax & Structure
python syntaxpython
error.filenameReturn Value
str | None
Diagnostic field when available.
Working Example
Example Snippetpython
error = SyntaxError("expected expression", ("demo.py", 3, 5, "x = ?\n", 3, 6))print(error.filename)