如果我有這樣的:Python - 我可以訪問誰打電話給我?
class A:
def callFunction(self, obj):
obj.otherFunction()
class B:
def callFunction(self, obj):
obj.otherFunction()
class C:
def otherFunction(self):
# here I wan't to have acces to the instance of A or B who call me.
...
# in main or other object (not matter where)
a = A()
b = B()
c = C()
a.callFunction(c) # How 'c' know that is called by an instance of A...
b.callFunction(c) # ... or B
儘管設計或其他問題,這只是探究精神的問題。
注:這有沒有改變otherFunction
簽名
但我想存取權限是誰喊我對象..不只是類的名稱。我wan't進入電影實例 – 2010-03-05 15:28:58
使用檢查模塊訪問' tb_frame'在stacktrace的每一項中,然後你可以在'f_locals ['self']'中找到實例' – 2010-03-05 15:30:54