title: Override module method where from...import is used
body: <p>I have a problem overriding the method where <code>from...import</code> statement is used. Some example to illustrate the problem:</p>
  <pre><code># a.py module
  def print_message(msg):
      print(msg)
  
  # b.py module
  from a import print_message
  def execute():
      print_message(&quot;Hello&quot;)
  
  # c.py module which will be executed
  import b
  b.execute()
  </code></pre>
  <p>I'd like to override <code>print_message(msg)</code> method without changing code in a or b module. I tried in many ways but <code>from...import</code> imports the original method. When I changed the code to</p>
  <pre><code>import a
  a.print_message
  </code></pre>
  <p>then I see my change.</p>
  <p>Could you suggest how to solve this problem?</p>
  <p>------------------ Update ------------------</p>
  <p>I tried to do that like below e.g.:</p>
  <pre><code># c.py module
  import b
  import a
  import sys
  def new_print_message(msg):
      print(&quot;New content&quot;)
  module = sys.modules[&quot;a&quot;]
  module.print_message = new_print_message
  sys.module[&quot;a&quot;] = module
  </code></pre>
  <p>But this is not working where I'm using <code>for...import</code> statement. Is working only for import a but as I wrote I don't want change code in b.py and a.py modules.</p>