[Answered ]-How to import a function from another directory file in python. Even have __init__.py file in that directory?

2👍

Python uses a period(.) operator to refer to the directories/modules starting from the current folder and moving upwards in the directory tree with each period.
For example, if you wish to import a file from python_file2.py and the file you are importing is contained in folder2 itself. This can be achieved by-
from . import <filename>
If you wish to import a file from python_file2.py and the file rests in folder1, you can add another period(.) to move one directory up and the statement will look like-
from ..folder1 import <filename>
filename is python_file1.py in your case. Hope this helps.

Leave a comment