同步阅读进度,多语言翻译,过滤屏幕蓝光,评论分享,更多完整功能,更好读书体验,试试 阅读 ‧ 电子书库
Chapter 21. Modules: The Big Picture
This chapter begins our in-depth look at the Python module, the highest-level program organization unit, which packages program code and data for reuse. In concrete terms, modules usually correspond to Python program files (or extensions coded in external languages such as C, Java, or C#). Each file is a module, and modules import other modules to use the names they define. Modules are processed with two statements and one important function:
import
Lets a client (importer) fetch a module as a wholefrom
Allows clients to fetch particular names from a moduleimp.reload
Provides a way to reload a module’s code without stopping PythonChapter 3 introduced module fundamentals, and we’ve been using them ever since. This part of the book begins by expanding on core module concepts, then moves on to explore more advanced module usage. This first chapter offers a general look at the role of modules in overall program structure. In the following chapters, we’ll dig into the coding details behind the theory.
Along the way, we’ll flesh out module details omitted so far: you’ll learn about reloads, the __name__ and __all__ attributes, package imports, relative import syntax, and so on. Because modules and classes are really just glorified namespaces, we’ll formalize namespace concepts here as well.
请支持我们,让我们可以支付服务器费用。
使用微信支付打赏
