DEV Community

[Comment from a deleted post]
Collapse
 
pystar profile image
Pystar • Edited

Great article however the order of import is swapped.
The "import " directive actually checks the sys.modules dictionary to see if the module has been imported before, if the module wasn't found, it will then start the search from the sys.path list of directories. Once found, it creates a module object from the "types.ModuleType" module and creates an entry in the sys.modules dictionary with the module name as the key and the module object as the value. It then compiles and executes the source of the module and creates a name entry in your globals() namespace.
Also, there is no difference between
from import name
Or import
If you check the sys.modules dict, you will always only find the name of the module. The only difference is in the globals() and the named reference to either the module.name or name only.