How to tell python to reload module whenever it sees import statement -
i'm writing program manage flow of processing data. user can write code of several method process data, called 'flow code', , tell program compare result of each method. code executed exec
.
there's git repo containing functions call, , user can import them in 'flow code'.
my question is, because user can change repo between each execution, how tell python reload modules when sees import statement in 'flow code'? current solution that, before executing line, check type of local variable of 'flow code' , reload if type moduletype
. however, inefficient. there better solution, hooks?
someone said imputil
can make hooks, documentation says:
deprecated since version 2.6: imputil module has been removed in python 3.
and i'm using python 2.7
use reload method.
e.g.
>>> import test >>> test.a 1 >>> test.a = 3 >>> test.a 3 >>> reload(test) <module 'test' 'test.pyc'> >>> test.a 1 >>>
Comments
Post a Comment