In the last lesson, I mainly talked aboutPython FunctionsTo share this lesson.Python Module.
The module has the following three features:
1CodeReuse:
For example, if you use python to perform website and member-related operations, such as user logon, password change, exit, and Query personal data
And other related information, because many websites require these functions, You can abstract these functions to form a user module, thus
You will writeProgram.
2. namespace Division:
The module is also the highest level of Python Program unit. The module converts code to a software package to avoid conflicting variable names.
The module is a good tool for organizing the system.
3. data sharing and service:
If you need an object to be used in many places, such as being called by functions or files, you can put it into the module at this time,
Import the data as needed to facilitate maintenance.
When talking about the python module, an important statement is import.
When I started to access import, I thought it was the same as the include method of PHP, But I just inserted the content of a file into another file.
In fact, import also performs other operations. This operation is the first time the program imports data to a specified file, it will perform the following steps:
1. Find the module File.
2. Compile the code into a bid.
3. Execute the module code to create the required object, such as the def statement of the python function. If you define it in the python module, it will also be executed.
If the Import Statement is executed for the second time, if the same module is imported, the program will skip the preceding three steps to directly extract
The loaded module object saves a lot of resource overhead. If your module contains many statements, it consumes resources to execute them once.
Today, I will give a general introduction to the python module. I may continue to talk about the python module in the next two classes. You can also take a look at what I mentioned earlier.
Knowledge about the python Module.