- 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.
- 黑客攻防從入門到精通(實戰秘笈版)
- Building a Game with Unity and Blender
- PostgreSQL Cookbook
- Vue.js入門與商城開發實戰
- Learning Bayesian Models with R
- Data Analysis with IBM SPSS Statistics
- Koa開發:入門、進階與實戰
- Functional Kotlin
- PySide 6/PyQt 6快速開發與實戰
- C#實踐教程(第2版)
- Instant Lucene.NET
- 小程序,巧應用:微信小程序開發實戰(第2版)
- Vue.js 2 Web Development Projects
- 細說Python編程:從入門到科學計算
- Three.js權威指南:在網頁上創建3D圖形和動畫的方法與實踐(原書第4版)