Python--5, Bag

Source: Internet
Author: User

Package

Package, which is a folder containing __init__.py files, is created to organize files (modules) in folders.
Python3, even if there is no __init__.py file in the package, the import can still be used. and Python2 in the package must have __init__.py to use.
The purpose of creating a package is not to run, but to be imported for use. Package is just a form of module, the essence of the package is the module (folder form).
As more and more function modules are used, it is necessary to organize the module files in folders to improve the structure and maintainability of the program.

Import principle: Generally in the import with points, the left side of the point must be a package, otherwise illegal. Can carry a series of points. The left side of use points after import can be packages, modules, functions, classes.

Import file, the resulting namespace name from the file, import package, the name of the resulting namespace is also derived from the file, that is, the __init__.py under the package, the import package is the essence of the import of the file

You can import the functions of the inner package in __init__.py to simplify the call.

It is important to note that the module imported from after import must not have a point after import. If you want to import all from the package API after import, in fact the statement only imports the name defined in the __init__.py file under the package API, we can define __all___ in this file.

Absolute Import and relative import
    • Absolute import: Starts with the top-level package.
    • Relative import: With. Or. The most important way to start

The packages and the modules that are included in the package are used for import, not to be executed directly. And the environment variable is to execute the file as the standard, the module under the sibling directory, cannot use import module_name when calling each other.

Python--5, Bag

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.