[問題] Class如何決定method

看板Python作者 (喵喵喵)時間12年前 (2012/04/25 22:31), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
class AAA(object): def A1(self,p): return p*1 def A2(self,p): return p*2 def CTRL(self,index,p): varname = 'A'+str(index) return self.varname(p) 使用 a = AAA() a.CTRL(1,100) [問題] 如何在物件內的CTRL中指定method名稱,然後傳回該method計算結果? 物件屬性是用 vars(self)[varname] 來操作,那method呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.230.192.150
文章代碼(AID): #1Fc0h6kV (Python)
文章代碼(AID): #1Fc0h6kV (Python)