Exception Attributes
SyntaxError.msg — exception attribute
Read the parser’s primary diagnostic message separately from source location fields. It can differ across Python versions and should not be used as a stable error identifier. The synthetic example supplies its own message.
Formal Syntax & Structure
python syntaxpython
error.msgReturn Value
str
Diagnostic field when available.
Working Example
Example Snippetpython
error = SyntaxError("expected expression", ("demo.py", 3, 5, "x = ?\n", 3, 6))print(error.msg)