Python basics-5 (packages and modules)

Source: Internet
Author: User

Packages and modules:

Module import, the module (XXX. py is compiled into XXX. PyC, so that you can directly use it next time)

Path of the python search module:
1)ProgramMain directory
2) ptyhonpath directory (if it has been set)
3) Standard Connection Library directory (usually in/usr/local/lib/python2.x /)
4) content of any. PTH file (if any). The new function allows users to add effective directories to the module search path.
List directories in one row in a text file with the. PTH suffix.
The four components are combined into SYS. Path.

The module is a python file that can be imported;

A package is a bunch of modules and sub-packages organized by directory. The directory must contain the _ init _. py package information file, which can be empty.

To create a package, create a folder named "package name" and create _ init __. you can store script files, compiled extensions, and sub-packages and import packages in this folder as needed. module.

Package and module import method:

1. Import, but when calling the import module method, you need to write "module name. Method"

2. Import XX as a to get the module alias

3. From module import method. To call the module method, you only need to write "method"

Built-in attributes:

_ Name _ indicates the class name in the class declaration. "_ main _" is returned for this class call. If it is called after other classes are imported, the class name is returned.

_ Bases _ is used as the base class Object tuples in the class declaration;
_ Dict _ the dictionary object used to save other attributes;
_ Doc _ class documents;
_ Module _ define the Module name of the class;

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.