1.註釋
- 塊註釋
塊註釋內部的段落通常只用一個#作爲空行的分隔
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# title :backup_full.py
# description :MySQL全量備份
# author :w.s.w
# date :20180601
# version :1.0
# notes :
# python_version :2.7
#==============================================================================
- 行內註釋
井前至少使用兩個空格和代碼語句分開,#後面有單個空格,注意避免使用無意義的註釋
x = x + 1 # 行內註釋
- 非公共方法註釋
非公共的方法沒有必要寫文檔說明,但是應該有一個描述方法具體作用的註釋,這個註釋應該在def那一行之後
def backup_synth(args):
# 增量備份
logger.info('backup_synth')
2.文檔說明
#!/usr/bin/env python
# png.py - PNG encoder/decoder in pure Python
#
# Copyright (C) 2006 Johann C. Rocholl <[email protected]>
# Portions Copyright (C) 2009 David Jones <[email protected]>
# And probably portions Copyright (C) 2006 Nicko van Someren <[email protected]>
#
# Original concept by Johann C. Rocholl.
#
# LICENCE (MIT)
"""
Pure Python PNG Reader/Writer
And now, my famous members
--------------------------
"""
# http://www.python.org/doc/2.2.3/whatsnew/node5.html
from __future__ import generators
__version__ = "0.0.18"
from array import array
- 公共類,公共方法
寫在def, class後,取一層縮進
def backup_alone(self, args):
"""單通道備份函數
Parameters:
filesystem(str): 文件系統
mountpoint(str): 掛載點
include(str): 包含文件
exclude(str): 排除文件
Returns:
pid(str): 進程號
"""