一个典型模块的内部结构:
- 起始行
- 模块文档(文档字符串)
- 模块导入
- (全局)变量定义
- 类定义(若有)
- 函数定义(若有)
- 主程序
样例代码:
#!/usr/bin/env python
#coding:utf-8
"this is a test module"
import sys
import os
debug = True
class FooClass(object):
"Foo class"
pass
def test():
"test function"
foo = FooClass()
if debug:
print 'ram test()'
if __name__ == '__main__':
test()