propety

1226 단어
class box(object):
    def __init__(self):
        self.width=0
        self.height=0
    def getsize(self):
        print "this is getsize(function)"
        return self.width,self.height
    def setsize(self,size):
        self.width,self.height=size
    def delsize(self):
        print "del ge dan"
        del self.width
        del self.height

    def __delattr__(self,name):
        print "nothing"
        super(box,self).__delattr__(name)
    def __getattr__(self,name):
        print "__getattr__----",name

    def __getattribute__(self,name):
        print "__getattribute__---",name
        return super(box,self).__getattribute__(name)
    size=property(getsize,setsize,doc="hello man",fdel=delsize)

    def smth():
        print "this is static method for box"

    smth=staticmethod(smth)

    def cmth(cls):
        print "this is class method for box",cls

    cmth=classmethod(cmth)

one=box()
one.size=100,50

======================= RESTART:/home/bottle/test.py ======================= >>> one.size getattribute--- size this is getsize(function) getattribute--- width getattribute--- height (100, 50)

좋은 웹페이지 즐겨찾기