How to tell python to reload module whenever it sees import statement
Question: I'm writing a program to manage the flow of processing data. User can write
code of several method to process data, called 'flow code', and tell my
program to compare the result of each method. The code is executed by `exec`.

There's also a git repo containing functions to call, and user can import them
in the 'flow code'.

My question is, because user can change repo between each execution, how to
tell python to reload modules when it sees an import statement in 'flow code'?
My current solution is that, before executing a line, check type of all local
variable of 'flow code' and reload it if the type is `ModuleType`. However,
this is very inefficient. Is there any better solution, like hooks?

Someone said `imputil` can make hooks, but the documentation says:

> Deprecated since version 2.6: The imputil module has been removed in Python
> 3.

And I'm using python 2.7


Answer: Use reload method.

e.g.

    
    
    >>> import test
    >>> test.a
    1
    >>> test.a = 3
    >>> test.a
    3
    >>> reload(test)
    <module 'test' from 'test.pyc'>
    >>> test.a
    1
    >>> 
    

