chaining method python code example
Example 1: class chain methods python
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
Example 2: class chain methods python
c = foo().line().my_print().bar().my_print()
assert c.kind == 'bar'