- 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.
- Kali Linux Web Penetration Testing Cookbook
- 編寫高質(zhì)量代碼:改善C程序代碼的125個建議
- 假如C語言是我發(fā)明的:講給孩子聽的大師編程課
- JavaCAPS基礎(chǔ)、應(yīng)用與案例
- 微服務(wù)從小白到專家:Spring Cloud和Kubernetes實(shí)戰(zhàn)
- Creating Mobile Apps with jQuery Mobile(Second Edition)
- Java SE實(shí)踐教程
- 移動互聯(lián)網(wǎng)軟件開發(fā)實(shí)驗(yàn)指導(dǎo)
- 計算機(jī)應(yīng)用基礎(chǔ)教程(Windows 7+Office 2010)
- Building Slack Bots
- 精通Spring:Java Web開發(fā)與Spring Boot高級功能
- 前端架構(gòu)設(shè)計
- Getting Started with RethinkDB
- C語言編程魔法書:基于C11標(biāo)準(zhǔn)
- H5匠人手冊:霸屏H5實(shí)戰(zhàn)解密