Introduction to Module and package concepts in Python _python

Source: Internet
Author: User

Module overview

If the module is a logical way to organize Python code, then the file is the method of organizing the module on the physical layer.
Therefore, * * A file is considered to be a stand-alone module, and a module can also be considered as a file. The file name of the module is modulo
The name of the block plus the extension. py. Unlike other languages that can import classes (Class), in Python you are importing module or module attributes * *.

Module name space

A namespace is a relational mapping of a name to an object.

Import Module

Import module overall (import)

Way One

Copy Code code as follows:

Import Module1
Import Module2
...
Import Modulen

Mode two
Copy Code code as follows:

Import module1[, module2[,... Modulen]]

Import module properties (from ... import ...)

Call From-import can import the name into the current namespace, which means you do not need to use the attribute/Period attribute identifier to access the module's identifier. For example, you need to access the var name in module modules so that it is imported:

Copy Code code as follows:

From module import name1[, name2[,... Namen]]

Rename a module or property after import
Copy Code code as follows:

Import ... as .....
From ... import ... as ...

Package

The package is a hierarchy of file directory structure, the module corresponds to a single file, the package corresponds to a directory. As with classes and modules, packages also use the period attribute to identify the elements that they are asked to visit. Import the modules in the package using the standard import and From-import statements.

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.