在调用的方法中获取调用者类实例(对象)?

时间:2015-06-16 11:06:51

标签: python instance inspect

我说我有

class A(object):
  def m1(self):
    B().m2()

class B(object):
  def m2(self):
    #return object of caller instance
    #let say 'a' is instance object this method was called from
    return a   

a = A().m1()

1 个答案:

答案 0 :(得分:0)

您可以传递调用者实例,并使其成为被调用函数本身的参数。像 -

这样的东西
setTimeout(function () {
    $.mobile.loading('show', {
        text: 'Chargement en cours...',
        textVisible: true,
        theme: 'a',
        html: '<div style="position:fixed;left:0;top:0;width:100%;height:100%;background-color:rgba(0,0,0,0.3);text-align: center"><span class="ui-bar ui-overlay-c ui-corner-all" style="text-align:center;display:inline-block"><img width="50px" height="50px" src="http://www.shougun.it/images/loading.gif" style="display:inline"/><br><h2>Chargement en cours...</h2></span></div>'
    });
}, 5);