title: Python: import function from an already imported module
body: <p>Suppose I have a python package <code>my_package</code> which contains a module <code>my_module</code> which contains a function <code>my_function</code>.</p>
  
  <p>I was trying to do the following import in python interactive shell:</p>
  
  <pre><code>&gt;&gt;&gt; from my_package import my_module
  &gt;&gt;&gt; my_module.my_function()            # =&gt; OK
  &gt;&gt;&gt; from my_module import my_function  # =&gt; ImportError: No module named my_module
  &gt;&gt;&gt; from my_package.my_module import my_function   # =&gt; OK
  </code></pre>
  
  <p>I am quite surprised at the <code>ImportError</code> at the third line above: since the <code>my_module</code> is already imported, why can I not import a function from it? Maybe I have some miss understanding on how python import system works, and any clarification will be highly appreciated!</p>
  
  <hr>
  
  <p>Here is the directory structure and source code.</p>
  
  <pre><code>my_package
    |- __init__.py
    |- my_module.py
  </code></pre>
  
  <p>Here is the <code>__init__.py</code> file</p>
  
  <pre><code>all = ["my_module"]
  </code></pre>
  
  <p>and here is the <code>my_module.py</code> file</p>
  
  <pre><code>def my_function():
      pass
  </code></pre>