- The Python Apprentice
- Robert Smallshire Austin Bingham
- 178字
- 2021-07-02 22:17:00
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.
- Apache ZooKeeper Essentials
- Java 9 Concurrency Cookbook(Second Edition)
- LabVIEW入門與實戰開發100例
- 差分進化算法及其高維多目標優化應用
- 網站構建技術
- INSTANT Passbook App Development for iOS How-to
- Node.js Design Patterns
- Android程序設計基礎
- Unity 3D/2D移動開發實戰教程
- 軟件項目管理實用教程
- 貫通Tomcat開發
- Java EE架構設計與開發實踐
- Java語言程序設計實用教程(第2版)
- Scratch編程從入門到精通
- Kohana 3.0 Beginner's Guide