在 Ipython (Jupyter-Notebook) 中使用 Pylint [英] Using Pylint in Ipython (Jupyter-Notebook)

查看:51
本文介绍了在 Ipython (Jupyter-Notebook) 中使用 Pylint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用 Jupyter-Notebook 时运行 Pylint 或任何等效程序.有没有办法以这种方式安装和运行 Pylint?

I want to run Pylint or any equivalent while using Jupyter-Notebook. Is there a way to install and run Pylint this way?

推荐答案

针对 pylint 更具体地回答问题.在 development/ci 环境(即命令行)中实现这一点的一种相对简单的方法是将 notebook 转换为 Python,然后运行 ​​linting.

To answer the question more specifically in regards to pylint. One relatively simple way to achieve that in a development / ci environment (i.e. command line) is to convert the notebook to Python and then run the linting.

假设您在 ./notebooks 文件夹中有笔记本,并且路径中有 jupyterpylint 命令,您可以运行以下内容:

Let's assume you have notebooks in the ./notebooks folder and you have the jupyter and pylint command in the path, you could run the following:

jupyter nbconvert 
    --to=script 
    --output-dir=/tmp/converted-notebooks/ 
    ./notebooks/*.ipynb
pylint /tmp/converted-notebooks/*.py

您可能需要配置 pylint,因为 notebook 风格与一般的 Python 模块略有不同.

You might want to configure pylint, as the notebook style is slightly different to a general Python module.

您可能想要禁用的一些规则:

Some rules that you might want to disable:

  • 毫无意义的陈述
  • 未赋值的表达式
  • 尾随换行
  • 错误的导入位置
  • 重新定义的外部名称
  • 无效名称

似乎单元格中的最大字符数(水平滚动之前)是 116 但这可能取决于其他因素.

It also appears that the maximum number of characters in a cell (before horizontal scrolling) is 116 but that might depend on other factors.

(例如,可以使用 --max-line-length--disable pylint 参数或通过 .pylintrc 文件)

(These options can for example be configured using the --max-line-length and --disable pylint arguments, or via the .pylintrc file)

这篇关于在 Ipython (Jupyter-Notebook) 中使用 Pylint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆