For the following Python code:
first.py
from second import Second
class First:
def __init__(self):
print 'Second'
second.py
from first import First
class Second:
def __init__(self):
print 'Second'
After creating the files and starting from the shell:
python first.py
I get an error: ImportError: cannot import name Second
Do other similar dynamic languages like Ruby have such a problem? The reason I ask is because I am facing this problem in a Django project, where 2 models are dependent on each other. I know that possible solutions are redesigning a project or importing it on demand. I just want to know if developers of other dynamic languages have encountered this problem.
source
share