Since your file (module) is called random.py
, import random
will import this very file.
Now, what does "import" mean?
The statement import something
will cause Python to lookup the name something
, starting with the current directory.
Therefore, import random
will result in an import of this very file, since its name will shadow the build-in random
.
Besides, if the name to import is already in the namespace, then the import
statement is ignored.
Once the module to import has been located, its code is executed.
As a result, the flow of your script is as follow:
- Lookup the
random.py
name
- Add
random
to the namespace
- Execute the code contained in
random.py
- The
random
name already exists in the namespace, so the import random
statement is ignored
- Print the text
- Print the text