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

  • The Python Apprentice
  • Robert Smallshire Austin Bingham
  • 240字
  • 2021-07-02 22:16:59

Modularity

Modularity is an important property for anything but trivial software systems as it gives us the power to make self-contained, reusable pieces which can be combined in new ways to solve different problems. In Python, as with most programming languages, the most fine-grained modularization facility is the definition of reusable functions. But Python also gives us several other powerful modularization mechanisms.

Collections of related functions are themselves grouped together a form modularity called modules. Modules are source code files that can be referenced by other modules, allowing the functions defined in one module to be re-used in another. So long as you take care to avoid any circular dependencies, modules are a simple and flexible way to organize programs.

In previous chapters we've seen that we can import modules into the REPL. We'll also show you how modules can be executed directly as programs or scripts. As part of this we'll investigate the Python execution model, to ensure that you have a good understanding of exactly when code is evaluated and executed. We'll round off this chapter by showing you how to use command-line arguments to get basic configuration data into your program and make your program executable.

To illustrate this chapter, we'll start with the code snippet for retrieving words from a web-hosted text document that we developed at the end of the previous chapter. We'll elaborate on that code by organizing it into a fully-fledged Python module.

主站蜘蛛池模板: 邮箱| 景泰县| 吴忠市| 崇阳县| 榆社县| 天全县| 承德市| 乐至县| 乡宁县| 资溪县| 内江市| 扶沟县| 济南市| 漳浦县| 云龙县| 抚宁县| 平遥县| 依兰县| 麻城市| 清原| 鄄城县| 宁都县| 武胜县| 梧州市| 宁津县| 乌恰县| 九江县| 阳原县| 临邑县| 察隅县| 江陵县| 克拉玛依市| 博乐市| 微山县| 宜宾县| 晋宁县| 大港区| 岳阳市| 富源县| 渭南市| 九江县|