Pycharm编码时-PEP8代码规范问题

在使用PyCharm时,最右边会有波浪线警告提示代码不符合PEP8代码规范。记录一下犯的错和解决方式

PEP8是风格错误,而不是编码错误。只是为了让代码更具有阅读性。

1)block comment should start with #

这个提示是在使用#注释的时候,需要在#后加上一个空格,然后再写注释内容

2)missing whitespace after ','  或  missing whitespace after ':'

在使用,或者:时,需要在后面加一个空格分割

3)whitespace before ','

提示,前面不需要空格,去掉空格即可

4)class name should use CamelCase convention

提示类名应该使用单词首字母大写的方式来命名,类名每个单词的首字母大写即可

5)expected 2 blank lines ,found 1

提示需要两个空行。只找到0或者1。加到两个空行即可

6)remove redundant parentheses

提示删除括号,如果类没有继承别的类。该类名之后可以不需要加上()。把()去掉即可

7)Triple double-quoted strings should be used for docstrings

应该使用三种双引号。写在类里和方法的注释使用了单引号。换成双引号的就可以了

8)too many blank lines(2)

提示空行过多,方法和方法之间一个空行就行

9)shadows name 'xxxx' from outer scope

命名冲突,提示外部变量和方法内的局部变量命名一样了。一种风险提示。改下变量名即可

10)Too broad exception clause

提示捕获异常的范围太广了,没有针对性。可以在try语句加上注释

# noinspection PyBroadException

11)argument name should be lowercase

参数名应该小写

12)missing whitespace around operator

等于号两边缺少空格

13)blank line at end of file

代码结束时,有多个空行,只需要一个空行

14)line too long(xxx > 120 characters)

单行代码长度过长,字符长度超过120

原文地址:https://www.cnblogs.com/syywy/p/12991353.html