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