Swind D.C. Xu Swind D.C. Xu - 5 months ago 23
Python Question

How can I just import a subdir and use "subdir.pythonfile.function" in python?

I have a python project with following structure:




----func.py (has a function a)


I want to use the function "a" in main.py. So I can

import subdir.func as F


But this is not what I want to do, I want to use

import subdir


How can I do that easily?

Solved, Thanks.


Keep your directory structure as it is and add this line in your init.py :

from . import func