[英]How to use Pylint or other linters with Jupyter Notebooks?
Is it possible to have a linter inside of a Jupyter Notebook?是否有可能在 Jupyter Notebook 内放置一个 linter?
pycodestyle
for Jupyter Notebook which is similar to pylint
.pycodestyle
Notebook 安装类似于 pylint 的pylint
。 You can use the below commands from inside a 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
You can use FlakeHell to run any number of linters supported by flake8 on entire notebooks您可以使用FlakeHell在整个笔记本上运行 flake8 支持的任意数量的 linter
If you want to use the black
linter in Jupyter:如果你想在 Jupyter 中使用
black
短绒:
pip install black "black[jupyter]"
black {source_file_or_directory}
If you want to auto-lint your notebooks with a pre-commit hook, you have to replace id: black
with id: black-jupyter
( more info here ).如果你想用 pre-commit 钩子自动 lint 你的笔记本,你必须用
id: black-jupyter
替换id: black
( 更多信息在这里)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.