My code is a bit complex so i'll show an example:
file A.py:
from B import B
class A():
def __init__(self):
self.id = 5
self.b = B()
file B.py
from A import A
class B():
def __init__(self):
self.id = 15
self.a = A()
This is the exception i get:
Traceback (most recent call last):
File "F:/Project/Code/A.py", line 1, in <module>
from B import B
File "F:\Project\Code\B.py", line 1, in <module>
from A import A
File "F:\Project\Code\A.py", line 1, in <module>
from B import B
ImportError: cannot import name B
All I want is A to contain an instance of B and B to contain an instance of A. I know that all I have to do is to convert them to a single file but I don't want to, my code is on much larger scales and my teacher force me to keep multiple short scripts instead of one long code.
Any suggestion will be appreciated.