<分区>
假设有一个定义了@property
的类:
class MyClass:
...
@property
def this_is_a_property(self):
return self.some_thing
...
def this_is_a_function(self, x):
...
return other_thing
通常,要检查属性是否为函数,我可以使用 inspect
模块中的 isfunction
。
import inspect
if inspect.isfunction(MyClass.__dict__['this_is_a_function']):
print('this_is_a_function',' is a function')
如何检查属性
?似乎没有 inspect.isproperty
函数。