passing function to a class using @property.setter decorator
<p>I am making a class that  i want to declare a variable which hold a function in it and i want to call them after i do some processing on some information.but i don't know how to use property decorator in this situation.
i already have this code:</p>

<pre><code>class MyClass:
    def __init__(self):
        self.callback = None
    def run():
        #do something here...
        result = self.callback(result)
        print(result)

def func1(result):
    result = result ** 2
    return result

def func2(result):
    result = result ** 4
    return result


class1 = MyClass()
class1.callback = func1
class1.run()
class1.callback = func2
class1.run()
</code></pre>

<p>my question is how i can use <code>@property</code> and <code>@property.setter</code> and <code>@property.getter</code> decorator for self.callback in this code?</p>

<p>I based on this code don't see a need for <code>properties</code> but here it is anyway.</p>

<pre><code>class MyClass:
    def __init__(self):
        self.__callback = None

    @property
    def cb(self):
        return self.__callback

    @cb.setter
    def cb(self, new_cb):
        self.__callback = new_cb
</code></pre>

python python-3.x callback python-3.5