python实现链式调用

在python中实现链式调用只需在函数返回对象自己就行了。

 1 class Person:
 2     def name(self, name):
 3         self.name = name
 4         return self
 5 
 6     def age(self, age):
 7         self.age = age
 8         return self
 9 
10     def show(self):
11         print "My name is", self.name, "and I am", self.age, "years old."
12 
13 p = Person()
14 p.name("Li Lei").age(15).show()
原文地址:https://www.cnblogs.com/MrFiona/p/7043039.html