訪問外部類的內部類在Python問題?
You're trying to access Outer's class instance, from inner class
instance. So just use factory-method to build Inner instance and pass
Outer instance to it.
1
2
3
4
5
6
7
8
9
10
11
12
class Outer(object):
def createInner(self):
return Outer.Inner(self)
class Inner(object):
def __init__(self, outer_instance):
self.outer_instance = outer_instance
self.outer_instance.somemethod()
def inner_method(self):
self.outer_instance.anothermethod()