I think what you are trying to do is to import FirstFolder
and SecondFolder
modules into main.
Now, trying to do from TopFolder import *
will result in a circular import, because main will be importing itself (main.py is part of *), which will do the import *
again, ... and so on. Furthermore, doing import *
is discouraged (see Why is “import *” bad?
).
A better solution is to define FirstFolder and SecondFolder as packages.
Then import specific modules from those packages in main.
TopFolder
|- FirstFolder
|- __init__.py
|- foo1.py
|- SecondFolder
|- __init__.py
|- foo2.py
|- main.py
In foo1.py:
def bar1():
return "bar 1"
In foo2.py:
def bar2():
return "bar 2"
In main.py:
# from TopFolder import * # Don't do this
from FirstFolder import foo1
from SecondFolder import foo2
print(foo1.bar1())
print(foo2.bar2())
Result:
$ python3 main.py
bar 1
bar 2