Nested class is not defined in itself

后端 未结 1 1151
北恋
北恋 2020-12-18 08:23

The following code successfully prints OK:

class B(object):
        def __init__(self):
            super(B, self).__init__()
            print          


        
相关标签:
1条回答
  • 2020-12-18 08:36

    B is available in the scope of A class - use A.B:

    class A(object):
        def __init__(self):
           self.B()
    
        class B(object):
            def __init__(self):
                super(A.B, self).__init__()
                print 'OK'
    
    A()
    

    See documentation on Python Scopes and Namespaces.

    0 讨论(0)
提交回复
热议问题