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

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.

主站蜘蛛池模板: 象山县| 壶关县| 广州市| 成安县| 凤山市| 江油市| 乐平市| 双城市| 克东县| 水城县| 朝阳县| 新野县| 黔西| 乐昌市| 新巴尔虎右旗| 和龙市| 瓮安县| 五家渠市| 黄石市| 华蓥市| 侯马市| 文成县| 高淳县| 梁平县| 和顺县| 鹤山市| 上饶市| 永德县| 大冶市| 安阳市| 墨脱县| 永清县| 海原县| 上杭县| 陈巴尔虎旗| 滦平县| 龙山县| 沙湾县| 博罗县| 乳山市| 松溪县|