0

In my project I have a directory (./Mylibs) with all my own libraries. To import them I simply write:

from Mylibs import configure, db, logger

This works fine. But during the execution I need to change something in the configure.py library and need this changes reimported. Therefor I did:

import importlib
importlib.reload(configure)

But this didn't work and I can't use the changes in my code. What did I do wrong?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Tom
  • 130
  • 1
  • 7
  • 1
    I read that you have to reconstruct the objects after the reload. Are you doing this? – Hassan Voyeau Sep 16 '20 at 16:29
  • I think you should redefine your import `configure = importlib.reload(configure)`. – Askold Ilvento Sep 16 '20 at 16:29
  • 1
    Does this answer your question? [How do I unload (reload) a Python module?](https://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module) – CryptoFool Sep 16 '20 at 16:32
  • for reloading configuration, maybe easier to use e.g. json loading. python module reload is for code, and indeed requires you take care to recreate the objects. – antont Sep 16 '20 at 16:38
  • @AskoldIlvento Yes, that didn't work. `UnboundLocalError: local variable 'configure' referenced before assignment` – Tom Sep 16 '20 at 16:57

0 Answers0