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

The difference between modules, scripts, and programs

We're sometimes asked about the differences between Python modules, Python scripts, and Python programs. Any .py file constitutes a Python module, but as we have seen modules can be written for convenient import, convenient execution, or, using the if __name__ == "__main__" idiom, both.

We strongly recommend making even simple scripts importable since it eases development and testing so much if you can access your code from the Python REPL. Likewise, even modules which are only ever meant to be imported in production settings benefit from having executable test code. For this reason nearly all modules we create have this form of defining one or more importable functions with a postscript to facilitate execution.

Whether you consider a module to be a Python script or Python program is a matter of context and usage. It's certainly wrong to consider Python to be merely a scripting tool — in the vein of Windows batch files or Unix shell scripts — as many large and complex applications have been built exclusively with Python.

主站蜘蛛池模板: 浪卡子县| 出国| 昭通市| 洞口县| 交口县| 长沙县| 巴青县| 柳江县| 黄平县| 永昌县| 田阳县| 喀喇| 普格县| 乌拉特中旗| 承德县| 清水河县| 桐城市| 祁阳县| 凯里市| 通辽市| 易门县| 万山特区| 黄石市| 杭锦后旗| 清流县| 绥滨县| 建平县| 贵南县| 长宁县| 如东县| 宁陕县| 高尔夫| 磐安县| 博罗县| 裕民县| 安多县| 桦川县| 逊克县| 蓝山县| 会昌县| 沙雅县|