[问题] PEP8 空白行 Blank Line

楼主: m87dd05 (八八里阿巴)   2017-10-27 15:31:51
最近在研究 Python PEP8 的撰写风格,
其中关于空白行的部分官网写到
Surround top-level function and class definitions with two blank lines.
Method definitions inside a class are surrounded by a single blank line.
Extra blank lines may be used (sparingly) to separate groups of related
functions. Blank lines may be omitted between a bunch of related one-liners
(e.g. a set of dummy implementations).
Use blank lines in functions, sparingly, to indicate logical sections.
Python accepts the control-L (i.e. ^L) form feed character as whitespace;
Many tools treat these characters as page separators, so you may use them to
separate pages of related sections of your file. Note, some editors and
web-based code viewers may not recognize control-L as a form feed and will
show another glyph in its place.
以下是我的理解
1. 空白行 Blank Line 指的就是一行空白
2. Function 与 class 要用两个空白行隔开
https://imgur.com/a/hJkjm
3. class 内的 method 用一个空白行隔开
https://imgur.com/a/hJkjm
4. 那import与class function又要几个空白行呢? 还是说这部分就没有规定
例如以下的写法有符合 PEP8 规范吗?
import os
import pandas
class TestClassA(object):
def __init__(self):
pass
class TestClassB(object):
'''
Summary line.
Bla bla bla bla.
'''
def __init__(self):
pass
def Test01():
print "TEST01!"
https://imgur.com/a/rQJHX
作者: uranusjr (←這人是超級笨蛋)   2017-10-27 15:54:00
通常是沿用其他 top-level 规则用两个空行
作者: darkgerm (黑骏)   2017-10-27 23:27:00
想测试程式有无符合 PEP8 可用 pylint

Links booklink

Contact Us: admin [ a t ] ucptt.com