[問題] 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 要用兩個空白行隔開

3. class 內的 method 用一個空白行隔開

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!"
作者: 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