I have a file test.py
class A(B):
def display(self):
print ("In A")
class B:
def display(self):
print ("In B")
I get the following error while run it Traceback (most recent call last):
File "/Users/praveen/Documents/test.py", line 1, in <module>
class A(B):
NameError: name 'B' is not defined
But if I change the order of declaration, It runs without any errors
class B:
def display(self):
print ("In B")
class A(B):
def display(self):
print ("In A")
Can anyone explain in detail why this weird error happens?
Bmeans until you've defined it. It's not really that weird.