Python module features

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.