在A类中从类B调用A类中的函数?

0 python oop

class A(object):
    class B(object):
        def __getitem__(self, key):
            # Obviously not the same self here...
            x = self.function_A_needs_as_well(key)  

    def function_A_needs_as_well(self, value):
        pass
Run Code Online (Sandbox Code Playgroud)

我希望这个例子不是太糟糕,至少有点自我解释.有人能告诉我如何从"B级"内部调用"function_A_needs_as_well"吗?

Dan*_*man 7

Python不是Java.嵌套类没有对其包含类的特殊访问权限.因此,几乎没有理由将它们嵌套.

如果B需要访问实例的实例A,则需要在某处传递它.