Python module and package mechanisms: import and from... import ..,

Source: Internet
Author: User

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.

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.