Reputation: 10315
Is there idiomatic way to reload python modules on edit? I am keeping configuration in my_config_module.py
file and want to automatically detect and load config changes. Currently I am trying something like this but I find it ugly and unsafe:
import my_config_module
import importlib
last_modification = os.stat('my_config_module.py').st_mtime
while True:
last_mod = os.stat('my_config_module.py').st_mtime
if last_mod != last_modification:
importlib.raload(my_config_module)
last_modification = last_mod
# main loop, some of my code
Upvotes: 1
Views: 252
Reputation: 1227
You should keep data in a separate file and reload it when it's modified (and thus, avoiding the need of reloading code).
Upvotes: 1