Inner Classes: How can I get the outer-class object at construction time?

前端 未结 7 853
死守一世寂寞
死守一世寂寞 2020-12-08 23:15

Consider the following Python (runs in 2.x or 3.x):

class Outer(object):
  pass

  class Inner(object):
    def __init__(self):
      print(\"Inner.self\", s         


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 00:14

    You should redesign your code not to use inner classes and to explicitly pass the instance of Outer to Inner when you make it, or not to require it.

提交回复
热议问题