python-Module, Package

Source: Internet
Author: User

1. What is a module?

1. A. Py is a module.

2. What are the benefits?

Improve maintainability and avoid conflict of function variable names.

3. How to Categorize:

Built-in--python installed, such as: sys, OS ....

Third-party open source-a py file contributed by developers around the world, installed via PIP install

Custom--Write your own py file

Note: The import module is equivalent to executing the module.

4. How is it called?

Import module: Importing modules directly

From module import XX: Importing a function into a module

From module import xx as XX: When you import a function and rename it, it is convenient to call it later.

From module.xx.xx Import *: Importing all functions

5. Find the path of the module: ", from the directory of the current PY--" from the Python and third-party library path to find

As long as the match in a directory, it will be imported immediately, no longer looking backwards.

6. Installation of open source modules:

Pip Install command, installed, with import XX can be called.

2. What is a package?

1. Package--is to put the relevant functions of the. py file in the same folder, this folder is called a package.

2. How to import modules between different packages?

Form Package Name Import XX

3. The path of the package to have (__init__.py) this file, to identify this folder is a package.

3. Import of Packages

Cross-Package Import

Now want to import the CRM directory under manage.py views.py

    

 from Import View

Why can I import directly? Because the environment variable has been added to ', this represents the path to the current folder is added to the environment variable, so the compiler can import directly.

Cross-module Import

Now want under the CRM view.py import proj under the setting.py, how to do?

1. If you write directly under view.py from Proj import setting

2. The operation will be error, said the path can not be found.

3. Why? is because there are no proj paths in the environment variables

  

Absolute import, relative import

  

  

  

  

     

        

  

python-Module, Package

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.