I found this method chaining in python, but even with it I couldn\'t understand method chaining in Python.
Here the goals are two: solve the coding problem and under
ther's an another interesting way of achieving this
class Foo:
def __init__(self, kind=[]):
self.kind = kind
def __getattr__(self, attrs):
self.attrs = attrs
return Foo(self.kind + [attrs])
def __call__(self):
return self.kind[::-1][0]
my_obj = Foo()
print(my_obj.bar.line.bar.bar.line())
with this code u don't have to pass .my_print()
but one thing to note here is the Foo class will take anything as argument like if we try print(my_obj.bar.line.bar.bar.circle())
it will return circle.
You can also edit this code to take the args while calling any function.