Apr-21-2019, 07:51 AM
I've simplified what I observed to the smallest example I could. Here it is:
Here are two .py files a1.py and a2.py,
a1.py:
If I modify a1 to become
Why does this happen!?
And what am I supposed to do when I want to import a function from a file to my main file, if the file also imports my main file?
Using from file import * seems to work, but I don't want to use *.
Here are two .py files a1.py and a2.py,
a1.py:
from a2 import bob cobe = 5a2.py:
from a1 import cobe bob = 4On running a1.py, I get the following error:
Output::Traceback (most recent call last):
File "FILE DIRECTORY", line 1, in <module>
from a1 import cobe
File "FILE DIRECTORY", line 1, in <module>
from a2 import bob
File "FILE DIRECTORY", line 1, in <module>
from a1 import cobe
ImportError: cannot import name 'cobe'
HOWEVER!If I modify a1 to become
from a2 import * cobe = 5I get no errors.
Why does this happen!?
And what am I supposed to do when I want to import a function from a file to my main file, if the file also imports my main file?
Using from file import * seems to work, but I don't want to use *.