Код: Выделить всё
class MyClass:
def __init__(self, condition):
self.condition = condition
def _method_1(self, param1, param2):
# Implementation for the first add_way method
print(f"_method_1 called with {param1} and {param2}")
def _method_2(self, param1, param2):
# Implementation for the second add_way method
print(f"_method_2 called with {param1} and {param2}")
@property
def method(self):
# How to return the correct method based on self.condition?
pass
# Example usage:
manager = WayManager(condition=True)
manager.method('value1', 'value2') # Should call _method_1 with 'value1' and 'value2'
manager.condition = False
manager.method('value3', 'value4') # Should call _method_2 with 'value3' and 'value4'
Подробнее здесь: https://stackoverflow.com/questions/792 ... property-i