[問題] PEP8 空白行 Blank Line

看板Python作者 (八八里阿巴)時間6年前 (2017/10/27 15:31), 編輯推噓0(002)
留言2則, 2人參與, 6年前最新討論串1/1
最近在研究 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 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.32.233.230 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1509089514.A.EB9.html

10/27 15:54, 6年前 , 1F
通常是沿用其他 top-level 規則用兩個空行
10/27 15:54, 1F

10/27 23:27, 6年前 , 2F
想測試程式有無符合 PEP8 可用 pylint
10/27 23:27, 2F
文章代碼(AID): #1Pyk3gwv (Python)
文章代碼(AID): #1Pyk3gwv (Python)