0

I have a function myFunc(a,b) defined in myMod under MyFolder. I import the function and call the function in the following way, it works.

from MyFolder.myMod import myFunc
myFunc(a,b)

Now I update my function . I would like to reload my function, but reload(myMod.myFunc) does not work. reload(MyFolder.myMod) does not work either. May i know the reason?

AAA
  • 695
  • 1
  • 7
  • 21
  • Possible duplicate of [How do I unload (reload) a Python module?](https://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module) – aydow Sep 03 '18 at 13:55
  • Hi aydow. Actually, i read the post you mentioned before i posted my own. The post seems does not work for me. I can run my function 'myFunc(a,b)' successfully, but it gives an error 'name 'myFunc' is not defined' when i run 'reload('myFunc)' – AAA Sep 03 '18 at 14:39

1 Answers1

0

Modules are compiled only once when you import them. And when you change them, python won't pick them up unless re imported i.e recompiled. So to get around that you can do this

import importlib
importlib.reload(module_name)

for python 3.x

And for python 2.x you can

reload(module_name)

Vineeth Sai
  • 3,389
  • 7
  • 23
  • 34