Is there a way to know the class to which one method belongs. In the following code I would like to build one decorator that could call either the method named get_f_name
or set_f_name
if the function f
has none argument or not. The idea is to build one decorator imitating the getter-setter syntax of jQuery.
To do that, I must know from which class the function f comes.
def jqueryize(f):
# ????
class Test():
def __init__(self):
self.string = "A little text..."
self.dictionnary = {
'key_1': 12345,
'key_2': [1, 2, 3, 4, 5]
}
self.boolean = True
@jqueryize
def data(
self,
string = None,
dictionnary = None,
boolean = None
):
...
def set_data(
self,
string,
dictionnary,
boolean
):
...
def get_data(self):
print(
self.string,
self.dictionnary,
self.boolean,
sep = "\n"
)