The following code successfully prints OK
:
class B(object):
def __init__(self):
super(B, self).__init__()
print 'OK'
class A(object):
def __init__(self):
self.B()
B = B
A()
but the following which should work just as same as above one raises NameError: global name 'B' is not defined
class A(object):
def __init__(self):
self.B()
class B(object):
def __init__(self):
super(B, self).__init__()
print 'OK'
A()
why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…