How can I just import a subdir and use "subdir.pythonfile.function" in python?
<p>I have a python project with following structure:<br>
project<br>
--subdir<br>
----__init__.py<br>
----func.py  (has a function a)<br>
--main.py<br></p>

<p>I want to use the function "a" in main.py. So I can<br>
<code>import subdir.func as F</code><br>
<code>F.a()</code></p>

<p>But this is not what I want to do, I want to use<br>
<code>import subdir</code><br>
<code>subdir.func.a()</code><br></p>

<p>How can I do that easily?</p>

<hr>

<p>Solved, Thanks.</p>

<p>Let me discuss here your current scenario first.
If you print files of 'subdir' here:</p>

<pre><code>    import subdir as SD
    print(SD.__file__)
</code></pre>

<p>It should show the <strong>init</strong>.pyc file name with absolute path.
So to resolve issue you have to import the func.py file in <strong>init</strong>.py file</p>

<pre><code>    from . import func
</code></pre>

python import subdirectory