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

如何在Python中获取存储在属性内部的函数?,python,reflection,Python,Reflection,假设prop=property(fget=somefunc1,fset=somefunc2) 给定prop,如何获得somefunc1和somefunc2 getter = ? setter = ? if (getter == None): do something else: do something else 我不能完全肯定我理解你想做什么。但是你不能直接访问prop.fget和prop.fset >>> def somefunc1(): pass .

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

给定
prop
,如何获得
somefunc1
somefunc2

getter = ?
setter = ?


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

我不能完全肯定我理解你想做什么。但是你不能直接访问
prop.fget
prop.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>
>>定义somefunc1():传递
...
>>>def somefunc2():传递
...
>>>属性(fget=somefunc1,fset=somefunc2)
>>>getter=prop.fget
>>>setter=prop.fset
>>>
>>>吸气剂
>>>塞特

是的,只是通过打印属性来解决这个问题。我不确定fget和fset是否为实际属性。是的,我一直在交互式shell中使用
dir()
来解决类似问题……或者在ipython会话中键入
smth.
并按
TAB