title: Override importing module's built-in functions from imported module
body: <p>I have an application where I would like to override certain functions when a condition occurs, for example:</p>
  
  <p>condition_check.py:</p>
  
  <pre><code>Flag = True
  import ctypes  # An included library with Python install.
  import inspect
  def MsgBox(msg):
      ctypes.windll.user32.MessageBoxA(0, msg, 'MsgBox', 1)
  def check():
      global print
      if Flag:
          def print(msg):
                  MsgBox(msg)
      else:
          pass
  </code></pre>
  
  <p>main.py:</p>
  
  <pre><code>## works
  from condition_check import *
  MsgBox('this is msgbox')
  print('this is a print')
  
  ## does not work
  import condition_check
  condition_check.MsgBox('this is msgbox')
  print('this is a print')
  </code></pre>
  
  <p>I understand that the <code>condition_check.py</code> is overriding its own <code>print</code> instead of the <code>main.py</code>'s <code>print</code>. I believe <strong>inspect</strong> library could be used for this purpose but I am not able to lookup an example.</p>