As a result of writing unorganized code, I got an error.
Traceback (most recent call last):
File "code1.py", line 7, in <module>
from code2 import my_function1
File "/home/ubuntu/code2.py", line 9, in <module>
import code3
File "/home/ubuntu/code3.py", line 6, in <module>
from code1 import my_function2
File "/home/ubuntu/code1.py", line 7, in <module>
from code2 import my_function1
ImportError: cannot import name 'my_function1'
The import is in an infinite loop.
Make it a local import instead of a global import.
code1.py
from code2 import my_function1
def main():
my_function1()
code1.py
def main():
from code2 import my_function1
my_function1()
This seems to be a symptomatic treatment, so I think it is basically better to clarify the master-slave relationship of imports.
ImportError: cannot resolve import name
Recommended Posts