Is it possible in Python to get the name of property currently being accessed, modified for deleted inside the function? For example, I've got this code with some pseudo-code inside:
class C(object):
def __init__(self):
self._x = None
@property
def x(self):
"""I'm the 'x' property."""
prop = get_current_property() #prop is set to 'x'
return self._x
@x.setter
def x(self):
"""I'm the 'x' property."""
prop = get_current_property() #prop is set to 'x'
return self._x
@property
def y(self):
"""I'm the 'x' property."""
prop = get_current_property() #prop is set to 'y'
return self._x
So the pseudo-code here is the get_current_property()
, which should work inside of the getter, setter and deleter methods for each property. Any way to do this?