5

I have a module that helps me with code and global variables, and a run file on a notebook. I use from my_module import * to import it and it works. When I change function definitions on the module, they autoreload on the notebook just fine, but the global variables I defined do not when I change them in the module - I have to restart the kernel.

Is there a way to achieve autoreload for them without putting them inside a function or class?

Thomas K
  • 39,200
  • 7
  • 84
  • 86
DeanLa
  • 1,871
  • 3
  • 21
  • 37

1 Answers1

1

Module named importlib allow to access to import internals. Especially, it provide function importlib.reload().

import importlib
importlib.reload(my_module)

importlib.reload() correctly re-read module and reset global variables.

importlib is only available since Python 3.1. For older version, you have to use module imp.

Jérôme Pouiller
  • 9,249
  • 5
  • 39
  • 47