class Foo:
def __init__(self,num):
self.age = num
@property
def get(self):
return self.age
@get.setter
def get(self,num1):
self.age = num1
class temp:
def __init__(self,time):
self.count = time
def get(self):
return self.count
def set(self,time1):
self.count = time1
def delete(self):
del self.count
print ('已删除')
p = property(get,set,delete,'修饰符property的使用')
#a = Foo(10)
#print (a.get)
#a.get = 20
#print (a.get)
b = temp(5)
print (b.p)
b.p = 10
print (b.p)
print (b.__dict__)
del b.p
print (b.__dict__)
b.p.__doc__
你用 类名.p.__doc__ 就行了。。 In [1]: class temp:
...: def __init__(self,time):
...: self.count = time
...: def get(self):
...: return self.count
...: def set(self,time1):
...: self.count = time1
...: def delete(self):
...: del self.count
...: print ('已删除')
...:
...: p = property(get,set,delete,'修饰符property的使用')
...:
In [2]: t = temp()
In [3]: t = temp(60)
In [4]: t.p
Out[4]: 60
In [5]: t.__doc__
In [6]: temp.__doc__
In [7]: temp.p.__doc__
Out[7]: '修饰符property的使用'
# 至于为什么是这样子? 我也不想去进一步了解,哈哈,反正这样的装饰器的__doc__特性,几乎用不上。更常用的是直接用@property
|