- Secret Recipes of the Python Ninja
- Cody Jackson
- 168字
- 2021-06-25 22:14:44
There's more...
If __all__ is not defined in __init__.py, then import * only imports the modules within the specified package, not all sub-packages or their modules. For example, from video.formats import * only imports the video formats; the modules in the effects/ directory will not be included.
This is a best practice for Python programmers: as the Zen of Python (https://www.python.org/dev/peps/pep-0020/) states, explicit is better than implicit. Thus, importing a specific sub-module from a package is a good thing, whereas import * is frowned upon because of the possibility of variable name conflicts.
Packages have the __path__ attribute, which is rarely used. This attribute is a list that has the name of the directory where the package's __init__.py file is located. This location is accessed before the rest of the code for the file is run.
Modifying the package path affects future searches for modules and sub-packages within the package. This is useful when it is necessary to extend the number of modules found during a package search.
- Flask Web開發入門、進階與實戰
- 零基礎學Python數據分析(升級版)
- Visual C++數字圖像處理技術詳解
- HTML5 APP開發從入門到精通(微課精編版)
- Learning R for Geospatial Analysis
- Service Mesh實戰:基于Linkerd和Kubernetes的微服務實踐
- Emgu CV Essentials
- Natural Language Processing with Python Quick Start Guide
- 算法圖解
- 從零開始學Python大數據與量化交易
- Spring Boot從入門到實戰
- 軟硬件綜合系統軟件需求建模及可靠性綜合試驗、分析、評價技術
- WCF全面解析
- JavaScript Mobile Application Development
- PHP程序設計高級教程