【发布时间】:2020-02-01 02:16:37
【问题描述】:
是否可以在 Jupyter Notebook 中使用 linter?
【问题讨论】:
标签: python jupyter-notebook pylint linter
是否可以在 Jupyter Notebook 中使用 linter?
【问题讨论】:
标签: python jupyter-notebook pylint linter
pycodestyle,类似于pylint。
您可以在 Jupyter Notebook shell 中使用以下命令:# install
!pip install pycodestyle pycodestyle_magic
# load
%load_ext pycodestyle_magic
# use
%%pycodestyle
def square_of_number(
num1, num2, num3,
num4):
return num1**2, num2**2, num3*
# Output
2:1: E302 expected 2 blank lines, found 0
3:23: W291 trailing whitespace
【讨论】:
您可以使用 FlakeHell 运行 flake8 on entire notebooks 支持的任意数量的 linter
【讨论】:
是的 - 您可以使用 nbQA 在 Jupyter Notebook 上运行任何标准 Python 代码质量工具
例如:
pip install -U nbqa pylint
nbqa pylint notebook.ipynb
免责声明:我是 nbQA 的作者
【讨论】:
如果你想在 Jupyter 中使用 black linter:
pip install black "black[jupyter]"
black {source_file_or_directory}
如果您想使用 pre-commit 挂钩自动 lint 您的笔记本,您必须将 id: black 替换为 id: black-jupyter (more info here)。
【讨论】: