【发布时间】:2018-04-04 12:10:30
【问题描述】:
假设我有一个 MyClass 类,它有一个使用 @property 装饰器创建的属性,如下所示:
class MyClass(object):
@property
def foo(self):
if whatever:
return True
else:
return False
假设我想使用 python 检查模块来获取定义属性的源代码。我知道如何为方法(inspect.getsource)执行此操作,但我不知道如何为属性对象执行此操作。有人知道怎么做吗?
【问题讨论】:
-
嗯。我很惊讶
inspect.getsource不能自动处理。 -
作为一项新功能可能值得提出要求
标签: python introspection inspect