官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 吉隆县| 天长市| 泸西县| 临湘市| 闽侯县| 衡东县| 会理县| 和政县| 灌云县| 焉耆| 永泰县| 霸州市| 梁平县| 新闻| 英吉沙县| 安康市| 策勒县| 策勒县| 革吉县| 甘泉县| 河源市| 德阳市| 娄底市| 盱眙县| 社会| 尼勒克县| 鄯善县| 琼中| 马公市| 黄冈市| 鄂托克前旗| 长治县| 定州市| 济南市| 思茅市| 黎川县| 安远县| 新竹市| 九台市| 稻城县| 上高县|