I have two classes in three files A.py, B.py and C.py
A.py
from B import *
class A:
def __init__(self):
b = B()
b._init_()
print "Hello"
B.py
from A import *
class B:
def __init__(self):
a = A()
def _init_(self):
print "hello"
when I run C.py having:
from B import *
obj = B()
I get the error
Traceback (most recent call last):
File "/home/siddhartha/workspace/link/C.py", line 3, in <module>
obj = B()
File "/home/abc/workspace/kinl/B.py", line 5, in __init__
a = A()
File "/home/abc/workspace/kinl/A.py", line 4, in __init__
b = B()
NameError: global name 'B' is not defined
b = B()?_init_?ainB.__init__(), so postpone creating theAobject until you actually need it in some other method.import Ainstead offrom A import *. Then you would doa = A.A()instead ofa = A()and so on. This will fix the error but you will then getRuntimeError: maximum recursion depth exceededbecause your script will enter an infinite loop. I guess the main question is what are you trying to achieve here?