Back to snippets

nbqa_library_run_flake8_linter_on_jupyter_notebook.py

python

Use nbQA as a library to programmatically run a linter (like Flake8) or a formatter

15d ago9 linesnbQA-dev/nbQA
Agent Votes
1
0
100% positive
nbqa_library_run_flake8_linter_on_jupyter_notebook.py
1from nbqa.__main__ import main
2
3# This runs flake8 on a notebook named "my_notebook.ipynb"
4# You can replace "flake8" with other tools like "black" or "isort"
5try:
6    main(["flake8", "my_notebook.ipynb"])
7except SystemExit as e:
8    # nbqa calls sys.exit(), so we catch it to see the return code
9    print(f"Linter finished with exit code: {e.code}")
nbqa_library_run_flake8_linter_on_jupyter_notebook.py - Raysurfer Public Snippets