python基础案例

时间:2021-08-29 03:57:18
【文件属性】:

文件名称:python基础案例

文件大小:1KB

文件格式:PY

更新时间:2021-08-29 03:57:18

python

python格式,基础案例你值得需要,#! /usr/local/bin/python # -*- coding: utf-8 -*- class CPrintMeBase(object): def __init__(self): print "init CPrintMeBase ..." def __str__(self): strRet = "" lMembers = dir(self) for strItem in lMembers: if strItem.startswith("m_"): exec("strCur = strItem + ' -> ' + str(self.%s)" % strItem) strRet += (strCur + "\n") if strRet.endswith("\n"): return strRet[:-1] return strRet def __del__(self): print "del CPrintMeBase ..." class CTest(CPrintMeBase): def __init__(self): super(CTest, self).__init__() #或CPrintMeBase.__init__(self) print "init CTest ... " self.m_strName = "CTest" self.m_nLevel = 2 def __del__(self): super(CTest, self).__del__() print "del CTest ... " def usage(): print "usage: python", sys.argv[0] + " xxx" print "eg1 : python ci_svr_agent.py xxx" if __name__ == "__main__": if len(sys.argv) == 1: usage() sys.exit() oCTest = CTest() print oCTest del oCTest #调用与否效果一样 class ClassName(superclass1, superclass1) data = value #类变量 def general_method(self, param): self.member = value @staticmethod def static_method(): print "This is class method" pass cls_name


网友评论