我在下面定义了一个类,它有一个名为“prop”的类属性,我希望打印出文档字符串“这是一个属性注释”。当前行为执行属性的 getter 并打印“getter”。
有没有办法设置类及其元类,以便我可以输入“帮助(MyClass.prop)”并获取文档字符串?
class _Metaclass(type):
@property
def prop(cls):
"""this is a property comment"""
print("getter")
return 1
@prop.setter
def prop(cls,value):
print("setter")
class MyClass(metaclass=_Metaclass):
"""this is a class comment"""
def func():
"""this is a function comment"""