python的典型文件结构

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lengye7/article/details/89179703

è¿éåå¾çæè¿°

#/usr/bin/env/ python            #(1) 起始行
# -*- coding: utf-8 -*-             #(2) 声明文件中的编码格式,在使用中文过程中,最好使用utf-8
"this is a test module"          #(3) 模块文档(文档字符串)
import sys
import os                 #(4) 模块导入

debug = True               #(5) (全局)变量定义
class FooClass (object):
    'foo class'
    pass                           #(6) 类定义(若有) 
def test():
    'test function'
    foo = FooClass()
    
    if debug:
        print 'ran test()'         #(7) 函数定义(若有) 
if  __name__ == '__main__':        #(8) 主程序 
    test()

猜你喜欢

转载自blog.csdn.net/lengye7/article/details/89179703