1
請看下面的例子:如何找到metamethod的名稱?
import types
methods = ['foo', 'bar']
def metaMethod(self):
print "method", "<name>"
class Egg:
def __init__(self):
for m in methods:
self.__dict__[m] = types.MethodType(metaMethod, self)
e = Egg()
e.foo()
e.bar()
,我應該怎麼寫,而不是"<name>"
,所以輸出是
method foo
method bar
這正是我需要的。 – rmflow