我想將某些函數調用爲單個值並返回集合結果。調用幾個函數並返回集合結果
class Foo:
def __init__(self, i):
self.i = i
def get(self):
return self.fn1(self.fn2(self.i)) #200
def fn1(self, i):
return i + i #10+10 = 20
def fn2(self, i):
return i * i #20*20 = 200
#...
foo = Foo(10)
print(foo.get())
有沒有更優雅的方式或模式?
不是真的。這有什麼問題? – 2012-02-12 17:13:50
@ S.Lott,只是不好,特別是如果你添加一些更多的方法,如:'self.fn1(self.fn2(self.fn3(self.i)))' – tomas 2012-02-12 17:17:45
我在考慮使用元類。 ..但這對於這麼簡單的事情可能太「瘋狂」了。 – 2012-02-12 17:35:37