Python是否可以从实例化的类函数中查看调用方法的“self”?

2024-06-16 09:28:46 发布

您现在位置:Python中文网/ 问答频道 /正文

class classB(object):
    def Bfunc1(self):
        "from here how can I access the 'self' of the calling class?"

class classA(object):
    def __init__(self):
        self._threadLocal = threading.local()

    def func1(self):
        self._threadLocal.x = 'stuff'
        cb = classB()
        cb.Bfunc1() <---

我正在尝试查看是否可以从classA到classB实例检索存储在threadlocal中的某些数据。我的问题是“self”引用被绑定到实例化的类。这可能吗


Tags: the实例fromselfhereobjectdefcan