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

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.

主站蜘蛛池模板: 闻喜县| 定远县| 芦山县| 南雄市| 分宜县| 桃园县| 临高县| 宁乡县| 昆山市| 牡丹江市| 平顺县| 绥化市| 综艺| 贡觉县| 墨脱县| 洛宁县| 达拉特旗| 甘孜县| 蕉岭县| 镇原县| 鸡泽县| 石城县| 石台县| 宁强县| 伽师县| 临安市| 沅陵县| 聂荣县| 安徽省| 万年县| 应城市| 澄城县| 子洲县| 临沂市| 绥阳县| 拉孜县| 牟定县| 诸城市| 蒙城县| 柳林县| 八宿县|