How to use _ _ all__ in python package
Today, I will talk to you about the use of _ _ all__ in the python package, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
1. In the package, _ _ all__ controls the list of modules that can be imported, that is, declares which modules can be imported.
2. The _ _ all__ in the package is declared in the _ _ init__ file, not written in any module.
There are multiple modules in a package, of which modules declared by all can be imported, and modules that are not declared cannot be imported.
Example
From demo import * # all modules in the import package hhhh.fun1 () # call the fun1 function of the hhhh module, output "this is function 1" my_module.fun1 () # call the fun1 function of the my_module module, and output "this is a package". After reading the above, do you have any further understanding of the use of _ _ all__ in the python package? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.