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

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.

主站蜘蛛池模板: 汉沽区| 德格县| 北碚区| 金秀| 白沙| 双峰县| 永兴县| 南汇区| 科技| 蒲江县| 九台市| 镇巴县| 江安县| 抚远县| 仁怀市| 瑞安市| 彩票| 南充市| 南开区| 汕尾市| 东乌珠穆沁旗| 巴彦淖尔市| 桃园市| 漠河县| 固始县| 筠连县| 涟源市| 资阳市| 桐柏县| 平昌县| 万山特区| 香河县| 巫溪县| 三台县| 扶沟县| 大田县| 金湖县| 武邑县| 同心县| 睢宁县| 陕西省|