Python PEP8 代码规范问题记录

本文详细记录了遵循Python PEP8代码规范时遇到的问题,包括文件末尾换行、缩进、逗号后空格、import语句、注释格式、函数命名、操作符周围空格等,并提供了相应的修复建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.PEP 8: W292 no newline at end of file

解决:在文件末尾加换行符(按回车即可)

Python PEP8 代码规范问题记录

PEP 8: no newline at end of file      代码末尾需要另起一行

PEP 8: indentation is not a multiple of four      缩进不是4的倍数,检查缩进

PEP 8: over-indented      过度缩进,检查缩进

PEP 8: missing whitespace after’,’      逗号后缺少空格

PEP 8: multiple imports on one line        不要在一行 import 中引用多个库

PEP 8: blank line at end of line       删除代码末尾的空格

PEP 8: at least two spaces before inline comment      代码与注释之间至少有两个空格

PEP 8: block comment should start with ‘#’      注释要以#加一个空格开始

PEP 8: inline comment should start with ‘#’      注释要以#加一个空格开始

PEP 8: module level import not at top of file         import 不在文件的顶部

PEP 8: expected 2 blank lines,found 0       需要两条空行

PEP 8: function name should be lowercase        函数名应该是小写字母

PEP 8: missing whitespace around operator       操作符 ( ' = '、' > '、' < ' 等 ) 前后缺少空格

PEP 8: E305 expected 2 blank lines after class or function definition, found 1      在类的定义以及函数定义之后需要空两行

PEP 8: E722 do not use bare 'except'     在捕获异常时,请尽可能的提及特定的异常,而不要使用裸except:子句。

其他

每行尽量不要超过80个字符,如果超过,可以用小括号“()”将多行内容隐式连接。(过长的url除外)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值