If I write such code, I can combine method calls in an instance of Object:
class ChainClassTest(object):
def order_by(self, *args, **kwargs):
print("I'm in order_by")
return self
def filter_by(self, *args, **kwargs):
print("I'm in filter_by")
return self
def get_list(self, *args, **kwargs):
print("I'm in get_list")
return self
if __name__ == "__main__":
cct = ChainClassTest()
cct.get_list().filter_by().order_by()
but what I would like to have is a call get_list()to do something dependent on the value given order_by. Of course, execution was order_by get_listalready completed at the time of execution , so I cannot do this. Or can I?
I thought about what to get get_list, filter_by, order_byand other similar methods to update the stack of function calls, and then do them all in the end ... except, of course, no way of knowing that you are at the end.
This will make it possible.
cct.get_list().filter_by().order_by()
cct.now_actually_do_it()
Where it now_actually_do_itconsumes a stack of functions created by the previous line of code, but I would really like to be able to do this on one line.
1. , now_actually_do_it , , .