We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a6dbd6f commit 687bcb2Copy full SHA for 687bcb2
chaining_method.py
@@ -0,0 +1,33 @@
1
+#!/usr/bin/env python
2
+# -*- coding: utf-8 -*-
3
+
4
+class Person(object):
5
6
+ def __init__(self, name, action):
7
+ self.name = name
8
+ self.action = action
9
10
+ def do_action(self):
11
+ print self.name, self.action.name,
12
+ return self.action
13
14
+class Action(object):
15
16
+ def __init__(self, name):
17
18
19
+ def amount(self, val):
20
+ print val,
21
+ return self
22
23
+ def stop(self):
24
+ print 'then stop'
25
26
+if __name__ == '__main__':
27
28
+ move = Action('move')
29
+ person = Person('Jack', move)
30
+ person.do_action().amount('5m').stop()
31
32
+#===== Output =====
33
+# Jack move 5m then stop
0 commit comments