您正在尋找的一般指導原則是在PEP257正確的引用內容,也許您只需要在行動中看到它。
你的功能是一個在線文檔字符串一個很好的候選人(「真的很明顯的情況下」):
def script_running(self, script):
"""Check if the script is running."""
通常,如果你說一個功能是檢查的東西就意味着它要返回True
或False
,但如果你喜歡,你能更具體:
def script_running(self, script):
"""Return True if the script is running, False otherwise."""
再次於一身行。
我可能也會改變你的函數的名字,因爲沒有必要強調函數的名字(腳本)是什麼。功能名稱應該是甜美的,簡短而有意義的。也許我會去:
def check_running(self, script):
"""Return True if the script is running, False otherwise."""
有時函數名,想象力是所有編碼很累,但你應該儘量嘗試做到最好。
對於多例子,讓我從google guidelines借用文檔字符串:
def fetch_bigtable_rows(big_table, keys, other_silly_variable=None):
"""Fetches rows from a Bigtable.
Retrieves rows pertaining to the given keys from the Table instance
represented by big_table. Silly things may happen if
other_silly_variable is not None.
Args:
big_table: An open Bigtable Table instance.
keys: A sequence of strings representing the key of each table row
to fetch.
other_silly_variable: Another optional variable, that has a much
longer name than the other args, and which does nothing.
Returns:
A dict mapping keys to the corresponding table row data
fetched. Each row is represented as a tuple of strings. For
example:
{'Serak': ('Rigel VII', 'Preparer'),
'Zim': ('Irk', 'Invader'),
'Lrrr': ('Omicron Persei 8', 'Emperor')}
If a key from the keys argument is missing from the dictionary,
then that row was not found in the table.
Raises:
IOError: An error occurred accessing the bigtable.Table object.
"""
這可能是一個辦法「總結自己的行爲並記錄它的參數,返回值(一個或多個),副作用例外情況,以及何時可以調用的限制(所有情況適用)「。
您可能也有興趣看看這example of pypi project,它意味着與Sphinx記錄。
我的2美分:準則是爲了給你你應該和不應該做的事情的想法,但他們沒有嚴格的規定,你必須盲從。所以最後選擇你覺得更好的東西。
我想清楚了的東西,在約擊中文檔字符串的行的最大長度另一個答案已經說。
PEP8告訴你「限制所有線路爲最多79個字符」即使在最後每個人都沒有80
這是80個charachters:
--------------------------------------------------------------------------------
,這可能是一個邊長的情況,你需要一點點長句子:
def my_long_doc_function(arg1, arg2):
"""This docstring is long, it's a little looonger than the 80 charachters
limit.
"""
就像一條線docstring,意思是對於真正明顯的情況,但是在你的編輯器(80字符限制)上有多行。