Swind D.C. Xu Swind D.C. Xu - 1 year ago 54
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.

Answer Source

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

from . import func
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download