This article mainly introduces the modules and package concepts in Python. This article describes the Module Overview, Module namespace, import module, and import module attributes (from... Import ...) For more information, see
Module Overview
If the module organizes Python code logically, the file is the method for organizing the module on the physical layer.
Therefore, ** a file is considered as an independent module, and a module can also be considered as a file. The module file name is the module
The Block name with the extension. py. Unlike other languages that can import classes, you can import module or module attributes in Python **.
Module namespace
A namespace is a ing between names and objects.
Import Module
Import Module)
Method 1
The code is as follows:
Import module1
Import module2
...
Import moduleN
Method 2
The code is as follows:
Import module1 [, module2 [,... moduleN]
Import module attributes (from... Import ...)
You can call from-import to import the name to the current namespace. This means that you do not need to use the attribute/period attribute identifier to access the module identifier. For example, you need to access the var name in the module to be imported as follows:
The code is as follows:
From module import name1 [, name2 [,... NameN]
The module or attribute is renamed after being imported.
The code is as follows:
Import......
From... import......
Package
A package is a hierarchical file directory structure. the module corresponds to a single file, and the package corresponds to a directory. in the same way as the class and module, the package also uses sentence points to identify their elements. Use the quasi-import and from-import statements to import modules in the package.