This a simple class, i just want to test the feature about __get__()
The code is :
class Des(object):
def __init__(self,num):
self.num = num
def __get__(self, obj, typ = None):
return self.num
class A(object):
des = Des(1)
print 'the des in class is ',des
a = A()
print 'the des in object is ',a.des
print a.__dict__
print A.__dict__
the output is :
the des in class is <Des object at 0x7f5fb550ded0>
the des in object is 1
{}
{'__dict__': <attribute '__dict__' of 'A' objects>, '__module__': '__builtin__', 'des': <Des object at 0x7f5fb550ded0>, '__weakref__': <attribute '__weakref__' of 'A' objects>, '__doc__': None}
my question is why the why the outputs of des
are des
is different (one is 1 type(int)
, one is object type(Des)
). And the output of a.__dict__
and A.__dict
is also different. What's the fucntion of __get__()
, and how to use it.