Exception Attributes
SyntaxError.text — exception attribute
Inspect the source text associated with the diagnostic. It can include a trailing newline, and may be unavailable. Treat source text as potentially sensitive when recording parser errors.
Formal Syntax & Structure
python syntaxpython
error.textReturn Value
str | None
Diagnostic field when available.
Working Example
Example Snippetpython
error = SyntaxError("expected expression", ("demo.py", 3, 5, "x = ?\n", 3, 6))print(repr(error.text))