Update module in python

When I import the MyClass class from the myModule.py file from the myModule.py dictionary, I do it like

 from myModules.myModule import MyClass 

How to reload this module after making changes to myModue.py file? Here are a few errors:

 reload(MyClass) # TypeError: reload() argument must be module reload(myModule) # NameError: name 'myModule' is not defined reload(myModules.myModule) # NameError: name 'myModules' is not defined 
+4
source share
1 answer

You must have a module to reboot. when you use from foo import bar , if bar not a module (it looks like it is not, in your case) you will have to use another import statement.

 from myModules.myModule import myClass # this will cause myModule.py to be evaluated. only myClass is in scope from myModules import myModule # since myModule has already been imported, myModule.py is not evaluated again. # but now myModule is in scope. reload(myModule) # this will cause myModule.py to be evaluated again. 

If for some reason you do not need two imports, the already imported module can also be found in sys.modules

+3
source

Source: https://habr.com/ru/post/1442971/


All Articles