Effective Python 读书笔记: 2 遵循PEP8风格值南

# -*- encoding: utf-8 -*-

import sys

reload(sys)
sys.setdefaultencoding('utf-8')

'''
第2条: 遵循PEP8风格值南

关键:
1 E128 continuation line under-indented for visual indent
解决方法:
https://blog.csdn.net/yageeart/article/details/37991331

问题原因:调用函数时,参数超长时,多行显示,首行不显示参数,余者按层次缩进显示,又如:
遇到if 中换行,and换行有问题或者无法换行,需要给整个if后面内容加上()
然后对and开始换行

2 E122 continuation line missing indentation or outdented
解决方法:

3 C901 'JSONView.get' is too complex (84)
解决方法: 将复杂方法拆分称若干个方法,减少复杂度

4 E111 indentation is not a multiple of four
解决方法:
缩进不是4的倍数
if 判断过长,则添加括号,并从and等符号后面换行

5 关于if的换行
and后面不要有空格,然后将and后面的全部换行后,手动再空4个空格
                    if (id is not None and
                            mydict is not None):

or将前后的条件都加上(), or后面不要有空格,然后将or后面的全部换行后,手动再空4个空格
                elif (s.get('type') == 'download') or\
                        (s.get('type') == 'upgrade'):

6 赋值语句中的 = 后面如果是多个运算符,则直接从
操作符号后面换行,不需要自己手动再空4个空格
                    during = (mydict[age + name] -
                              data(str(generated)))

参考:
Effectiv Python 编写高质量Python代码的59个有效方法


'''

猜你喜欢

转载自blog.csdn.net/qingyuanluofeng/article/details/88583886