Python Frequently Asked Questions, Release 3.9.5 Chapter 2. Programming FAQ 34 will continue to work with the old version of the imported objects. If the module contains class definitions, existing class instances will not be updated to use the new class definition. This can result in the following paradoxical behaviour: The last step fails, because Python isn’t done with interpreting$_{foo}$ yet and the global symbol dictionary for$_{foo}$ is still empty. The same thing happens when you use$_{import foo}$, and then try to access$_{foo.foo_var}$ in global code. There are (at least) three possible workarounds for this problem. Guido van Rossum recommends avoiding all uses of$_{from <module> import ...}$ , and placing all code inside functions. Initializations of global variables and class variables should use constants or built-in functions only. This means everything from an imported module is referenced as$_{<module>.<name>}$ . Jim Roskind suggests performing steps in the following order in each module: van Rossum doesn’t like this approach much because the imports appear in a strange place, but it does work. Matthias Urlichs recommends restructuring your code so that the recursive import is not necessary in the first place. These solutions are not mutually exclusive. Consider using the convenience function$_{import_module()}$ from$_{importlib}$instead: z =importlib.import_module( 'x.y.z ') For reasons of efficiency as well as consistency, Python only reads the module file on the first time a module is imported. If it didn’t, in a program consisting of many modules where each one imports the same basic module, the basic module would be parsed and re-parsed many times. To force re-reading of a changed module, do this: Warning: this technique is not 100% fool-proof. In particular, modules containing statements like from modname import some_objects import importlib import modname importlib.reload(modname) • active code (including globals that are initialized from imported values). • $_{import}$statements • exports (globals, functions, and classes that don’t need imported base classes) • bar.foo_var = foo.foo_var • bar imports foo (which is a no-op since there already is a module named foo) • Empty globals for foo are created • foo is compiled and starts executing • foo imports bar • Empty globals for bar are created • bar is compiled and starts executing 2.7.4 __import__(‘x.y.z’) returns <module ‘x’>; how do I get z? 2.7.5 When I edit an imported module and reimport it, the changes don’t show up. Why does this happen?