Python import module problem

When we import a module, have you ever thought about what will happen if I repeat the import? What did you do when importing? let's see

1. First, we create a new demo,py with only one output statement

2. Import the demo multiple times, and after running it, you can see that it is only executed once

3. Let's look at the two lines of code in the figure below. You can see that the demo module and path are in the output.

Actually it looks like this:

1. First check whether it has been imported from sys.modules, if not, find it from the path

2. Then create a namespace for this module

3. Execute the file and put the names in the file into the namespace