Last active
June 15, 2017 02:42
Revisions
-
yuba revised this gist
Jun 15, 2017 . No changes.There are no files selected for viewing
-
yuba revised this gist
Jun 15, 2017 . 5 changed files with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ class C: def __init__(self, n): self.n = n def m(self, x, y): This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ class C: def __init__(self, n): self.n = n def m(self, x, y): This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ class C: def __init__(self, n): self.n = n def m(self, x, y): This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ class C: def __init__(self, n): self.n = n def m(self, x, y): This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ class C: def __init__(self, n): self.n = n def m(self, x, y): -
yuba revised this gist
Jun 15, 2017 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,10 +10,11 @@ def wrap_m(self): """ 与えられたオブジェクトのmというメソッドをいじって差し替えます """ m_ = self.m # これが差し込むいたずら関数。クロージャでself(というかここではself.m)を知っている。 def my_func(x, y): # selfを引数にとらない関数 m_('%s兆' % (x * 1000), '%s兆' % (y * 1000)) self.m = my_func -
yuba revised this gist
Jun 15, 2017 . No changes.There are no files selected for viewing
-
yuba created this gist
Jun 15, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ class C: def __init__(n): self.n = n def m(self, x, y): print('self.n:%s, x:%s, y:%s' % (self.n, x, y)) i = C(1) C.m # クラスメソッド参照 i.m # インスタンスメソッド参照 C.m(i, 5, 5) # クラスメソッド参照はselfを渡す必要あり i.m(5, 5) # インスタンスメソッド参照はselfを渡す必要なし This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ self.n:1, x:5, y:5 self.n:1, x:5, y:5 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ class C: def __init__(n): self.n = n def m(self, x, y): print('self.n:%s, x:%s, y:%s' % (self.n, x, y)) def my_func(self, x, y): # selfを第一引数にとる関数 self.m('%s兆' % (x * 1000), '%s兆' % (y * 1000)) C.my_m = my_func i = C(1) i.my_m(5, 5) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ self.n:1, x:5000兆, y:5000兆 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ class C: def __init__(n): self.n = n def m(self, x, y): print('n:%s, x:%s, y:%s' % (self.n, x, y)) def my_func(x, y): # selfを引数にとらない関数 C('???').m('%s兆' % (x * 1000), '%s兆' % (y * 1000)) i = C(1) i.my_m = my_func i.my_m(5, 5) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ class C: def __init__(n): self.n = n def m(self, x, y): print('n:%s, x:%s, y:%s' % (self.n, x, y)) # ここですでにiというインスタンスが存在しているのがポイント i = C(1) self = i def my_func(x, y): # selfを引数にとらない関数 self.m('%s兆' % (x * 1000), '%s兆' % (y * 1000)) i.my_m = my_func i.my_m(5, 5) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ self.n:1, x:5000兆, y:5000兆 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ class C: def __init__(n): self.n = n def m(self, x, y): print('n:%s, x:%s, y:%s' % (self.n, x, y)) def wrap_m(self): """ 与えられたオブジェクトのmというメソッドをいじって差し替えます """ # これが差し込むいたずら関数。クロージャでselfを知っている。 def my_func(x, y): # selfを引数にとらない関数 self.m('%s兆' % (x * 1000), '%s兆' % (y * 1000)) self.m = my_func i1 = C(1) i2 = C(2) wrap_m(i1) # i1インスタンスのmメソッドをラップしちゃうぞ i1.m(5, 5) i2.m(5, 5) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ self.n:1, x:5000兆, y:5000兆 self.n:2, x:5, y:5