Override module method where from...import is used
<p>I have problem to override method where from...import 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("Hello")

# c.py module which will be executed
import b
b.execute()
</code></pre>

<p>I'd like to override print_message(msg) method without changing code in a or b module. I tried in many ways but from...import imports original method. When I changed code to</p>

<pre><code>import a
a.print_message
</code></pre>

<p>than I see my change.</p>

<p>Could you suggest my how to solve this problem?<br>
Thanks in advance for any little example.</p>

<p>Best Regards</p>

<p>------------------ Update ------------------<br>
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("New content")
module = sys.modules["a"]
module.print_message = new_print_message
sys.module["a"] = module
</code></pre>

<p>But this is not working where I'm using for...import 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>
