How to reload python module from itself?
- by mivulf
I have a python module with a lot of variables. These variables are used and changed by many other modules. And I want to reload this module from itself when it happens (for refresh).
How to do that?
# ==================================
# foo.py
spam = 100
def set_spam(value):
spam = value
foo = reload(foo) # reload module from itself
# ==================================
# bar.py
import foo
print foo.spam # I expect 100
# assume that value changes here from some another modules (for example, from eggs.py, apple.py and fruit.py)
foo.set_spam(200)
print foo.spam # I expect 200