12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 18CHAPTER 18Modules: The Big Picture18This chapter begins our in-depth look at the <strong>Python</strong> module, the highest-level programorganization unit, which packages program code and data for reuse. Inconcrete terms, modules usually correspond to <strong>Python</strong> program files (or extensionscoded in external languages such as C, Java, or C#). Each file is a module, and modulesimport other modules to use the names they define. Modules are processed withtwo statements, and one important built-in function:importLets a client (importer) fetch a module as a wholefromAllows clients to fetch particular names from a modulereloadProvides a way to reload a module’s code without stopping <strong>Python</strong>Chapter 3 introduced module fundamentals, and we’ve been using them ever since.Part V begins by expanding on core module concepts, then moves on to exploremore advanced module usage. This first chapter offers a general look at the role ofmodules in overall program structure. In the next and following chapters, we’ll diginto the coding details behind the theory.Along the way, we’ll flesh out module details omitted so far: you’ll learn aboutreloads, the _ _name_ _ and _ _all_ _ attributes, package imports, and so on. Becausemodules and classes are really just glorified namespaces, we’ll formalize namespaceconcepts here as well.Why Use Modules?In short, modules provide an easy way to organize components into a system by servingas self-contained packages of variables known as namespaces. All the namesdefined at the top level of a module file become attributes of the imported module385

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!