0

I've got a project where I'm regularly updating code across multiple files. The problem is that sometimes older files in current use are importing from out of date files, is it possible to have some kind of centralised import file that imports the most up to date files into the current file with vanilla python 2.7.10?

Bitmap Image
  • 201
  • 3
  • 7
  • 1
    I believe sys.modules already does that job for you, along with reloading modules: http://www.diveintopython.net/file_handling/more_on_modules.html What you can do is `reload` (Python 2) or `importlib.reload` (Python 3) the module, which should overwrite the module in sys.modules (although not necessarily in each namespace, I'm not sure on this). You could ensure that each module accesses a fresh import by doing a sys.modules['module_name'] each time you access the module, so rather than do: `module.Class()`, do `sys.modules['module'].Class()` – Alex Huszagh Jan 03 '16 at 18:02
  • 1
    I think you should try this http://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module – wolfsgang Jan 03 '16 at 18:03

0 Answers0