如何在Python中获取存储在属性内部的函数



假设prop = property(fget = somefunc1, fset = somefunc2)

给定prop,我将如何获得somefunc1somefunc2

getter = ?
setter = ?

if (getter == None):
    do something
else:
    do something else

我不完全确定我是否理解您想要做的事情。但是您不能只访问prop.fgetprop.fset吗?

>>> def somefunc1(): pass
...
>>> def somefunc2(): pass
...
>>> prop = property(fget = somefunc1, fset = somefunc2)
>>> getter = prop.fget
>>> setter = prop.fset
>>>
>>> getter
<function somefunc1 at 0x023085B0>
>>> setter
<function somefunc2 at 0x023085F0>

相关内容

  • 没有找到相关文章