title: How can I achieve override a function call in the middle of another function?
body: <p>I am writing a Python3 program, in which I need to be able to override some method on the fly. My folder structure is more like:</p>
  
  <pre><code>./
  prog.py
  methods/
    add.py
    minus.py
  </code></pre>
  
  <p>In <code>prog.py</code> I want to call a <code>calc()</code> function which is defined both in <code>add.py</code> and <code>minus.py</code>. I wish that the code can work as if:</p>
  
  <pre><code>def prog('foo'):
      from method.foo import calc
      calc()
  </code></pre>
  
  <p>But importing in the middle of a function seems awful and might slow down the whole program. Is there any workaround that can achieve the same effect?</p>
  
  <p>I am trying to be flexible so that I can add more methods later on, so I avoid if statements and import all the modules at once.</p>