So, I've tried a lot of things from the Internet, but nothing helps me. I have main.py file and I have a neighbour folder 'A' and folder 'B' in 'A'. How can I import .py files from 'B' to main.py? P.S I've tested variant about init.py, but it causes unresolved import error
Asked
Active
Viewed 94 times
0
-
2Possible duplicate of [Python import module from sibling folder](https://stackoverflow.com/questions/14886143/python-import-module-from-sibling-folder) – Paritosh Singh Mar 17 '19 at 12:11
-
Duplicate. Here is one way to do it: https://stackoverflow.com/questions/4383571/importing-files-from-different-folder – luanpo1234 Mar 17 '19 at 12:18
1 Answers
0
Folder A
and B
should have empty __init__.py
files in it. More about this in docs
a_file.py
def im_a_function():
print("Printing from A folder function")
b_file.py
from A.a_file import im_a_function
def im_b_function():
im_a_function()
main.py
from B.b_file import im_b_function
im_b_function()
running main.py file will print out message Printing from A folder function

Povilas
- 627
- 2
- 6
- 19