chain method in python code example
Example 1: class chain methods python
c = foo().line().my_print().bar().my_print()
assert c.kind == 'bar'
Example 2: how to chain methods i n pytohn clases
class foo():
def __init__(self, kind=None):
self.kind = kind
def my_print(self):
print (self.kind)
return self
def line(self):
self.kind = 'line'
return self
def bar(self):
self.kind='bar'
return self