Usage:
Import Module 1[, Module 2, Module 3 ...]
OS Top-level modules
Os.path Non-top modules
As equals renaming
The essence of import:
The interpreter is responsible for loading the module separately, initializing it separately, generating a Module object, the current scope generating an identifier of the same name, mapping to the Module object, and then using this identifier to access the resources of the module object. The module is not directly referenced, or the source code of the module is loaded into the current space.
The include in the HTML language means that the source code of the other files is included directly to generate a new source file.
Example 1:
' Functools '] <module ' Functools ' from ' c:\\python\\lib\\functools.py ' >//This Module object is a modules module type <function wraps at 0x0000020a133f1d90>[finished in 0.4s]
The class, method, and property of the module can be invoked with "." After import, because the module is initialized to an object.
Example 2:
'os ']
Example 3:
' P '] Ntpath[finished in 0.3s]
Summarize:
1. When importing a top-level module directly (such as import OS), the interpreter is responsible for loading the module separately, initializing the module, generating a Module object, and binding an identifier with the same name in the current namespace.
When used, you need to use the format "module name. Method ()".
2. When a non-top-level module is imported (such as import Os.path), only the object identifier of the top-level module is generated in the current namespace and the path identifier is not generated.
When used, it can only be used with the full hierarchical relationship of "os.path.exists ()".
3. When the imported non-top-level module uses an as statement (such as import Os.path as P), the current namespace is bound to the object identifier "P".
When used, the module resources can be used in a "p.exists ()" manner.
Introduction to the modular import of Python (i)