Page Views: Stats unavailable
In modular programming, we often encounter such a scenario:
Write a Python module and use the import my_module to import in the form of When changes are made to the module, any changes will not be recognized even if they are re-imported This makes module debugging very difficult.
So, how to solve this problem?
Write a Python module and import it as import my_module. When changes are made to the module, any changes in it will not be recognized even if they are re-imported, which makes module debugging very difficult.

For efficiency reasons (the import must find the file, compile it into bytecode, and run the code), the Python shell imports each module only once per session. For example, there is a module named hello.py that contains the following code:
Print ('Hello, Python')
What happens if you import it multiple times?
>>> import hello
Hello, Python!
>>>
>>> import hello
>>> import hello
As you can see, the code was executed only once. That is, the module was imported only once.
If you change a module that has already been imported in the Python shell and then re-import the module, Python will think "I have already imported the module and do not need to read the file again", so the change will be invalid.
There are several ways to solve this problem:
reload() function. In many cases, it is enough after editing a module.PS: The second way is mainly introduced below - reload(), other ways to try on your own.
reload() is a concise way provided by Python that behaves differently in different versions of Python:
>>> import importlib
>>> import hello
Hello, Python! # content before modification
>>>
>>> importlib.reload (hello)
I am coming... # modified content
<module 'hello' from '/home/wang/Projects/hello.py'>