问题描述
我正在使用 Python 3.6.2 运行 Pylint 1.7.2.Pylint 显示以下错误:
I'm running Pylint 1.7.2 with Python 3.6.2. Pylint is showing the following error:
Invalid function name "create_maximization_option_dataframe" (invalid-name)
我在我的代码中定义了一个函数:
I define a function like so in my code:
def create_maximization_option_dataframe(file_name):
PEP8 风格指南基本上只是说:
The PEP8 style guide basically just says:
函数名称应为小写,单词之间用下划线分隔以提高可读性.
据我所知,我遵循函数名称的所有格式规则.Pylint 是否有一些我不知道的内置最大函数名称长度规则?我可以很容易地忽略 Pylint 错误,但我想了解为什么会首先发生这种情况.
As far as I'm aware I'm following all the formatting rules for a function name. Does Pylint have some built-in maximum function name length rule that I'm not aware of? I can ignore the Pylint error easily enough but I want to understand why this is happening first.
推荐答案
通过执行 pylint pylint --generate-rcfile
来制作配置文件.范围取决于你把它放在哪里.引用 https://docs.pylint.org/en/1.6.0/run.html
Make a config file by doing pylint pylint --generate-rcfile
. The scope of that depends where you put it. Quoting https://docs.pylint.org/en/1.6.0/run.html
- 当前工作目录中的pylintrc
- .pylintrc 中的当前工作目录
如果当前工作目录在Python 模块,Pylint 向上搜索 Python 模块的层次结构直到它找到一个 pylintrc 文件.这允许您指定编码基于模块的标准.当然,目录是如果包含 init.py 文件,则判断为 Python 模块.
- pylintrc in the current working directory
- .pylintrc in the current working directory
If the current working directory is in a Python module, Pylint searches up the hierarchy of Python modules until it finds a pylintrc file. This allows you to specify coding standards on a module-by-module basis. Of course, a directory is judged to be a Python module if it contains an init.py file.
由环境变量PYLINTRC命名的文件
The file named by environment variable PYLINTRC
如果你有家不是/root 的目录:您的主目录中的 .pylintrc
.config/pylintrc 在您的主目录中
if you have a home directory which isn’t /root: .pylintrc in your home directory
.config/pylintrc in your home directory
/etc/pylintrc
/etc/pylintrc
听起来您需要选项 5 或 6.
Sounds like you need option 5 or 6.
在pylintrc中,找到这个位
In the pylintrc, find this bit
# Regular expression matching correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$
将接近尾声的 30 改为 40 左右.
Change that 30 near the end to 40 or so.
这篇关于Pylint 无效的函数名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!