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

Introduction

Python modules are the highest-level components of Python programs. As suggested by their name, modules are modular, capable of being plugged in with other modules as part of an overall program to provide better separation of code while combining together to create a cohesive application.

Modules allow easy reuse of code, and provide separate namespaces to prevent variable shadowing between blocks of code. Variable shadowing involves having duplicate variables in different namespaces, possibly causing the interpreter to use an incorrect variable. Each Python file a developer creates is considered a separate module, allowing different files to be imported into a single, overall file that forms the final application.

Realistically, any Python file can be made a module by simply removing the .py extension; this is most commonly seen when importing libraries. Python packages are collections of modules; what makes a package special is the inclusion of an __init__.py file. We will cover the differences in detail later, so for now just recognize that there are several names for the same items.

主站蜘蛛池模板: 河西区| 余庆县| 赤峰市| 横山县| 大渡口区| 门头沟区| 衡南县| 鹿邑县| 临颍县| 永康市| 甘肃省| 宁乡县| 涡阳县| 布尔津县| 宁安市| 皋兰县| 新河县| 同仁县| 郁南县| 太保市| 介休市| 乌鲁木齐市| 北海市| 正蓝旗| 于都县| 什邡市| 莱芜市| 衡南县| 泰兴市| 定州市| 临洮县| 抚宁县| 化德县| 临潭县| 石屏县| 平舆县| 平阴县| 无棣县| 禄丰县| 张家港市| 黎平县|