我有这段代码用于测试数据描述符
class DataDescriptor(object):
def __init__(self):
self.value = 1990
def __get__(self,obj,cls):
print "__get__ in Data descriptor"
return self.value
def __set__(self,obj,value):
self.obj = value
print "__set__ in Non Data Descriptor"
def __del__(self,obj):
print "__del__ in Non Data Descriptor"
del self.obj
class NonDataDescriptor(object):
def __get__(self,obj,cls):
print "__get__ in Non Data descriptor"
class C(object):
dd = DataDescriptor()
ndd =NonDataDescriptor()
def __init__(self):
self.__value = 1
cobj = C()
cobj.dd
当我执行它时,我只能看到打印语句,但我看不到我在 get 函数中退休的实际值
我的输出只有这个
__get__ in Data descriptor