怎样得到一个方法的caller对象

class C:
    str = {}
    def __init__(self):
        self.d = D()
        self.name = "sophia tang"

    def f(self):
        self.d.f1(self.str)
        print "self.str==",self.str

class D:
    def f1(self, str):
        str['a'] = 'hello'
        self.f2(str)
        import inspect
        caller = inspect.stack()[1][0].f_locals['self']
        print caller.name


    def f2(self, str):
        str['b'] = "sophia"

posted @ 2011-10-01 13:53  SophiaTang  阅读(174)  评论(0编辑  收藏  举报