get descriptor from instance

Gabriel Genellina gagsl-py2 at
Thu Feb 19 00:15:10 CET 2009

En Wed, 18 Feb 2009 20:48:17 -0200, Alan G Isaac <aisaac at>  

> What is a reliable way to get the
> the property object for an instance attribute?
> (Or more generally, to get the descriptor
> controlling an attribute?)
> If class ``A`` defines the property ``x`` and ``a``
> in an instance of ``A``, then you can just use
> ``type(a).__dict__['x']`` to get the property object.
> But this will not work if the property is inherited.


py> class A(object):
...   def getx(self): return 1
...   x = property(getx)
py> class B(A):
...   pass
py> b=B()
py> b.x
py> B.x
<property object at 0x00B8A690>
py> type(b).x
<property object at 0x00B8A690>
py> getattr(type(b),'x')
<property object at 0x00B8A690>

Gabriel Genellina

More information about the Python-list mailing list