资源介绍
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
- 上一篇: 书签源码,分享各自书签
- 下一篇: Python 语言实现的抓取网页内容与列文件目录