更改默认的 python 编码风格
在 python 中,我遵循 camelCase 命名风格。我用“pylint”检查了我的代码,它因不遵循 lower_case_with_underscores 样式而给出错误。我还使用 netBeans IDE 进行编码。此 IDE 会针对不遵循 lower_case_with_underscores 样式发出警告。
如何告诉 pylint 和 netBeans 我遵循驼峰命名风格,而不是小写字母带下划线?
谢谢。
In python i'm following camelCase Naming style. I checked my code with "pylint" and it gives error for not following lower_case_with_underscores style. Also i use netBeans IDE for coding. This IDE gives warning for not following lower_case_with_underscores style.
How to tell pylint and netBeans that i'm following camelCase naming style, not lower_case_with_underscores??
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 pylint --generate-rcfile > ~/.pylintrc 获取标准的
pylintrc
。编辑该文件,转到 [BASIC] 部分,然后更改以下正则表达式:
function-rgx=_?_?[az][A-Za-z0-9]{1,30}$
method-rgx=_?_?[az][A-Za-z0-9]{1,30}$
attr-rgx=_?_?[az][A -Za-z0-9]{1,30}$
argument-rgx=_?[az][A-Za-z0-9]{1,30}$
variable-rgx=_?[az][A-Za-z0-9]{1,30}$
inlinevar-rgx=_?[az][A-Za-z0-9] {1,30}$
您可能还想在执行此操作时更改
module-rgx
,并查看您可能想要自定义以适合您的风格的其他设置。Use
pylint --generate-rcfile > ~/.pylintrc
to get a standardpylintrc
.Edit the file, go to the [BASIC] section, and change the following regexps:
function-rgx=_?_?[a-z][A-Za-z0-9]{1,30}$
method-rgx=_?_?[a-z][A-Za-z0-9]{1,30}$
attr-rgx=_?_?[a-z][A-Za-z0-9]{1,30}$
argument-rgx=_?[a-z][A-Za-z0-9]{1,30}$
variable-rgx=_?[a-z][A-Za-z0-9]{1,30}$
inlinevar-rgx=_?[a-z][A-Za-z0-9]{1,30}$
You may also want to change
module-rgx
while you are at it, and look around for other settings that you may want to customize to suite your style.接受的答案已过时。现在更简单了:
使用 pylint --generate-rcfile > ~/.pylintrc 获取标准 pylintrc。
编辑该文件,转到 [BASIC] 部分,并将不同的
...-naming-styles
更改为camelCase
。Accepted answer is outdated. Now its much simpler:
Use
pylint --generate-rcfile > ~/.pylintrc
to get a standard pylintrc.Edit the file, go to the [BASIC] section, and change the different
...-naming-styles
tocamelCase
.对于 netbeans 8.0.2 ...
工具 -->选项 -->编辑-->提示-->蟒蛇-->命名约定 -->功能-->混合大小写
for netbeans 8.0.2 ...
Tools --> Options --> Editor --> Hints --> Python --> Naming Conventions --> Functions --> mixedCase
在 VS-Code 中,使用此
settings.json
条目将变量命名样式和函数命名样式设置为“camelCase”,根据您的要求选择参数,
Pylint 文档 :
In VS-Code use this
settings.json
entry to have variable naming style and function naming style set to "camelCase",choose arguments as per your requirements,
Pylint Documentation: