登录 注册
当前位置:主页 > 资源下载 > 31 > 基础的Python案例

基础的Python案例

  • 更新:2024-08-08 21:33:14
  • 大小:1KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:网络基础 - 网络技术
  • 格式:PY

资源介绍

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