Si j'ai ceci:Python - Puis-je accéder à l'objet qui m'appelle?
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
Malgré la conception ou d'autres problèmes, c'est seulement une question d'un esprit curieux.
Note: Ceci doit être fait sans changerotherFunction
signature
Mais je veux OBJECT qui acces me appelle .. pas seulement le nom de la classe .. Je wan't à l'instance acces –
Utilisez le module pour inspecter l'accès ' tb_frame' dans chaque élément de la pile et ensuite vous pouvez trouver l'occurrence dans 'f_locals ['self']' –