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

前端 未结 7 868
死守一世寂寞
死守一世寂寞 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:12

    See Access outer class from inner class in python (https://stackoverflow.com/a/35118717/3787376)
    for a simple reliable answer I made that only uses variables, attributes, functions and classes - no special code.

提交回复
热议问题