Skip to content

Note

Click here to download the full example code or to run this example in your browser via Binder

SyntaxError

Example script with invalid Python syntax

Traceback (most recent call last):
  File "/home/runner/work/mkdocs-gallery/mkdocs-gallery/.nox/publish-3-9/lib/python3.9/site-packages/mkdocs_gallery/gen_single.py", line 857, in execute_code_block
    code_ast = _parse_code(bcontent, src_file, compiler_flags=compiler.flags)
  File "/home/runner/work/mkdocs-gallery/mkdocs-gallery/.nox/publish-3-9/lib/python3.9/site-packages/mkdocs_gallery/gen_single.py", line 743, in _parse_code
    code_ast = compile(bcontent, src_file, "exec", compiler_flags | ast.PyCF_ONLY_AST, dont_inherit=1)
  File "/home/runner/work/mkdocs-gallery/mkdocs-gallery/examples/no_output/plot_syntaxerror.py", line 13
    Invalid Python code
            ^
SyntaxError: invalid syntax
# -*- coding: utf-8 -*-
"""
Example with SyntaxError
========================

Sphinx-Gallery uses Python's AST parser, thus you need to have written
valid python code for Sphinx-Gallery to parse it. If your script has a
SyntaxError you'll be presented the traceback and the original code.
"""
# Code source: Óscar Nájera
# License: BSD 3 clause

Invalid Python code

Total running time of the script: ( 0 minutes 0.001 seconds)

Launch binder

Download Python source code: plot_syntaxerror.py

Download Jupyter notebook: plot_syntaxerror.ipynb

Gallery generated by mkdocs-gallery