No, Python modules do not work this way. Using import to import one module into another namespace, you configure the name of the imported module in the namespace of the calling module. This means that you generally do not want to use the same name for any other purpose in the calling module.
By hiding import os inside the module, Python allows a script call (a script test in your case) to decide what it wants to import into its own namespace. Perhaps the caller of the script say os = "hello world" and use it as a variable that has nothing to do with the standard os module.
It is true that the os module loads only once. All that remains is the question of the visibility of the name os inside each module. To import the same module more than once, there is no (well, negligible) performance. The module initialization code is launched only at the first input of the module.
source share