一、内容格式
1、注释部分:模块名及简介(一般用一行写完),模块描述(包含各类方法),其它描述(注意点,功能,示例等,可以分多段)
2、导入模块:Import XXX
3、全局变量定义:wantobjects = 1
4、私有变量定义:_names = sys.builtin_module_names(不能用'from module import *'导入 )
5、私有类定义:(不能用'from module import *'导入 )
def _cnfmerge(cnfs):
"""Internal function.""" (注释内容只在本文件中阅读,不需要写的非常详细)
6、命名空间定义:(在模块中使用__all__属性可避免在相互引用时的命名冲突,help时会特别导入命名空间中模块的说明内容)
# Note: more names are added to __all__ later. (命名空间的注释,可选)
__all__ = ["altsep"]
7、类定义:注释部分-类名及简介(一般用一行写完),其它描述-(注意点,功能,示例等,可以分多段)代码里变量函数等定义方式和模块定义方式基本相同
8、方法定义:注释部分-类名及简介(一般用一行写完),其它描述-(注意点,功能,示例等,可以分多段)代码里变量函数等定义方式和模块定义方式基本相同
l 模块内容示例如下:
R’’’ os - OS routines for NT or Posix depending on what system we're on.
This exports:
- all functions from posix, nt or ce, e.g. unlink, stat, etc.
- os.path is either posixpath or ntpath
Programs that import and use 'os' stand a better chance of being
portable between different platforms.
Example (Hello, World):
.......
‘’’
Import XXX
wantobjects = 1
_names = sys.builtin_module_names
def _cnfmerge(cnfs):
"""Internal function."""
........
# Note: more names are added to __all__ later.
__all__ = ["altsep"]
class Event:
"""Container for the properties of an event.
Instances of this type are generated if one of the following events occurs:
‘’’
.........
def split(p):
‘’’Split a pathname.
Return tuple (head, tail) where tail is everything after the final slash.
Either part may be empty.
‘’’
二、编码格式
1、变量定义:
n _xxx 不能用'from module import *'导入
n __xxx__ 系统定义名字
n __xxx 类中的私有变量名