Python module and package mechanisms: import and from... import ..,
Use import or from... import in python to import the corresponding module.
The module is actually a collection file of some functions and classes. It can implement some corresponding functions. When we need to use these functions, we can directly import the corresponding modules into our programs, we can use it. This is similar to the include header file in C language. In Python, we use import to import the required modules.
(ModuleIs A. py file)
(PackageIs a folder containing. py files. The folder also contains a special file _. init _. py)
Usage:
Import package1 # import module # from module import function # from package1 import module # from package1.package2 import # import module. function1 #
Note
1 import: load all the language names in the source file (so the module is a file ).
2. The import statement can appear anywhere in the program. However, no matter how many times the import Statement is used, the code in each module is loaded and executed only once, subsequent import statements only bind the module name to the module object created in the previous import.