Import essence, import
I. Module: it is used to logically organize python code (variables, functions, classes, logic, and implement a function). In essence, it is the python file ending with py.
1.1 import method:
Import module
Import module1, module2
From module import logger
From module import logger as frank
1.2 import essence: Explain the python file again
1.3 import module_name
In fact, it is equivalent to copying all the code of module_name. To use it, use the variables and functions module_name.name, module_name.logger.
1.4 from module_name import name
In fact, it is equivalent to copying the name part of module_name to this part. You can directly reference name = 'Alex 'and directly call the variable name.
Ii. Package: logically organize a module, which is essentially a directory (a directory with the _ init _. py file)
1.1 import essence: Execute the _ init _. py file under the package directory
1.2 Import Optimization:
Instance, the following code needs to constantly call the module module_test. If there are 200 such calls, you have to find them back and forth, affecting efficiency, in this case, you can convert "import module_test" to "from module_test import test"
def logger(): module_test.test() print(' in the logger')def search(): module_test.test() print("in the search")