About bloggers : Former Internet manufacturer tencent staff , Network security giant Venustech staff , Alibaba cloud development community expert blogger , WeChat official account java Quality creators of basic notes ,csdn High quality creative bloggers , Entrepreneur , Knowledge sharers , Welcome to your attention , give the thumbs-up , Collection .
In the actual development process , You will often encounter many identical or very similar operations , At this time , Code that implements similar operations can be encapsulated as functions , Then call the function where you need it . This can not only realize code reuse , It can also make the code more organized , Increase code reliability . Now let's introduce python The function package of .
In order to organize the modules , Usually, multiple modules are placed in one directory . We will Python The directory where the module files are located is called package , And there must be __init__.py file ( The content of the file can be empty ).
It has the following package structure :
package_1
|—— init.py
|—— module_1.py
|—— module_2py
|—— module_3py
main.py
for example : If main.py Want to call package_1 Module in package module_1 Medium f() function :
import package_1.module_1 # The import module
package_1.module_1.f() # Call function
# You can also use the following statement to implement
from package_1 import module_1 # The import module
module_1.f() # Call function
1、 Liao Xuefeng's official website
2、python Official website
3、Python Programming case tutorial
The above is about Python Function package related knowledge of , You can refer to it , If you think it's good , Welcome to thumb up 、 Collection 、 Looking at , Welcome to wechat search java Basic notes , Relevant knowledge will be continuously updated later , Make progress together .