Override module method where from…import is used

With your a and b modules untouched you could try implementing c as follows:

import a

def _new_print_message(message):
    print "NEW:", message

a.print_message = _new_print_message

import b
b.execute()

You have to first import a, then override the function and then import b so that it would use the a module that is already imported (and changed).

Leave a Comment