Why are such imports not allowed?
FILE: b.py
class B:
def __init__(self):
print "B"
import a
a = A()
FILE: a.py
class A(B): ###=> B is not defined
def __init__(self):
print "A"
When I try to execute b.py, he said that B is not defined. I do not understand the "import"?
Thank you very much if you can point out the problem.
The next work on your code will be:
==== FILE: b.py ====
class B:
def __init__(self):
print "B"
import a
if __name__ == "__main__":
a = a.A()
==== FILE: a.py ====
import b
class A(b.B): ###=> B is not defined
def __init__(self):
print "A"
Please note the differences:
Files (modules) are namespaces, if you import "a", you refer to its class A as "aA".
You need to import b into a.py if you want to use it.
, , , . , , .