Python basic----modules, packages

Source: Internet
Author: User

a module

㈠ What is a module?

A module is a file that contains the Python definition and declaration, and the filename is the suffix of the module name plus the. Py.

Why do ㈡ use modules?

If you quit the Python interpreter and then re-enter, then the functions or variables you defined previously will be lost, so we usually write the program to a file so that it can be persisted and executed in Python test.py when needed, when test.py is called a scripting script.

With the development of the program, more and more functions, in order to facilitate management, we usually divide the program into a file, so that the structure of the program is clearer and easier to manage. In this case, we can not only use these files as scripts to execute, but also as a module to import into other modules, to achieve the reuse of functionality,

㈢ How do I use modules?

1 Import
2 from ... import ...
3 module as script execution
4 Module Search Path
5 compiling Python files
6 standard modules
7 dir () function
Two packs
1 Import
2 from ... import ...
3 __init__.py file
4 from GLANCE.API import *
5 Absolute Import and relative import
6 Importing packages individually

Python basic----modules, packages

Related Article

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.