Exception Attributes

SyntaxError.offset — exception attribute

Locate the reported starting column within the diagnostic source line, using one-based coordinates. Tabs and source representation can complicate display; do not treat it as a terminal column width. For some errors the location can be unavailable or special.

Formal Syntax & Structure

python syntaxpython
error.offset

Return Value

int | None

Diagnostic field when available.

Working Example

Example Snippetpython
error = SyntaxError("expected expression", ("demo.py", 3, 5, "x = ?\n", 3, 6))print(error.offset)
Python Reference