class Test:
func = self.func2 # default: func is func2 by default
# tried Test.func2 as well and Pycharm shows error
def __init__(self, func=None):
if func is not None:
self.func = func
def func1(self):
pass
def func2(self):
pass
Can anyone advise how to achieve something like the above?
I have tried setting the func parameter to default to func2 in the constructor too but this also errors.
so later, somewhere in the class Test, I can just call self.func instead of repeatedly running conditions to find out whether func1 or func2 should be used
self.func()
**** SOLUTION (what I did) ****
in the main.py:
t = Test(func=Test.func1)
t.func(t, **kwargs)
this should successfully call t.func1 (or t.func2 if specified) with access to the t instance_attributes through a call of higher order method t.func
funcpassed to__init__be eitherfunc1orfunc2?