Function Analysis of the _ init _. py file in the Python module package,

Source: Internet
Author: User

Function Analysis of the _ init _. py file in the Python module package,

This example describes the _ init _. py file function in the Python module package. We will share this with you for your reference. The details are as follows:

It has been more than a year since django was used for development __. the significance of the existence of the py file. It is too important to see the Introduction to it.

Module package:

A package is usually a directory. The first file under the directory is _ init _. py. Then there are some module files and subdirectories. If there are also _ init _. py in the subdirectory, It is the sub-package of this package.

Like this:

Package1/_ init _. py Module1.py Module2.py Package2
Package1/Package2/_ init _. py Module1.py Module2.py

We can import a package as follows:

Import Package1

You can also call a sub-module and sub-package:

From Package1 import Module1 from Package1 import Package2, import Packag1.Module1, import Packag1.Package2

You can go deep into several layers of Package Structure:

From Package1.Package2 import Module1, import Package1.Package2. Module1

In general, I think the essence of the package should be in the _ init _. py file.

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.