Skip to content Skip to sidebar Skip to footer

Delay An Evaluation / Lazy Evaluation In Python

I want to delay the evaluation of a call to a member function of an instance of a class until this instance actually exists. Minimum working example: class TestClass: def __in

Solution 1:

a simple lambda works. When called, the function will fetch test_class variable from the current scope, and if it finds it, that will work, like below:

delayed_evaluation_0 = lambda : test_class.get_variable_0()
test_class = TestClass(3)
print(delayed_evaluation_0())

prints 3

Post a Comment for "Delay An Evaluation / Lazy Evaluation In Python"