For example, I want to be able to inject a behavior if I want to inside a function, but if I don't have a behavior, I want it to have a default behavior
class TestDefaultParam:
def defaultBehavior(file1, file2):
return 2
def action(file1, file2, behave=defaultBehavior):
return behave(file1, file2)
if __name__ == '__main__':
some = TestDefaultParam()
print(some.action("test", "test"))
If this isn't possible how can I change behavior of action at will?
with this code I get this error:
Traceback (most recent call last):
File ".\test.py", line 10, in <module>
print(some.action("test", "test"))
File ".\test.py", line 6, in action
return behave(file1, file2)
TypeError: 'str' object is not callable