Concepts of Modules & Package modules (module):
In the process of computer program development, as the program code more write more, in a file code will be more and more long, more and more difficult to maintain. In order to write maintainable code, we grouped many functions into separate files, so that each file contained relatively few code, and many programming languages used the existence of this kind of organization code. In Python, a . py file is called a module
What are the benefits of using modules?
The greatest benefit is that the maintainability of the code is greatly improved.
Second, writing code does not have to be zero-based, and when a module is written, it can be used elsewhere, and we often refer to other modules when writing programs, including Python built-in modules and modules from third parties.
There are three types of modules:
- Python Standard library
- Third-party modules
- Application Custom Modules
In addition, the use of modules can also avoid the function name and variable name conflict, the same name of the functions and variables can be completely separate modules, so we do not have to consider the name when writing the module conflict with other modules, but also note that do not conflict with the built-in function name
Module Import Method 1, import statement
Import module name, module name
When we use the import statement, how does the Python interpreter find the corresponding file? The answer is that the interpreter has its own search path, which exists in Sys.path.
2. From...import statement
From ModName Import function name
This is equivalent to taking a function from the ModName module to the current one, and of course, the code in the ModName module is loaded again when the interpreter executes the code.
3. From...import * Statement
From ModName Import *
This provides an easy way to import all functions in a module, but this method is not recommended, and many Python programmers do not use this method, because the introduction of other sources of naming, it is likely to overwrite the existing definition
Python's Path to growth "fifth article": Python-based module