ABSTRACT

With what we have seen so far we have an interesting portfolio of resources for Python programming. We can read files, do some data processing and store its results. Although programs made so far are very short, it is easy to imagine that they could grow up to a size that it may be difficult to manage. There are several resources that can used to modularize source code in a

way that we may end up with a small program that calls pre-made code blocks (also called routines in other computer languages). This approach favors code re-usability and readability. Both features also help maintenance, since you have to debug only one code implementation, regardless of how many times this code is used. As an additional advantage, it helps to improve performance, since any optimization on a modularized code benefits all the code that calls it. For some authors, code modularizing is “The Greatest Invention in Com-

puter Science,”1 I don’t know if this is the “greatest invention” or not, but sure it is a fundamental concept that you can’t live without if you plan to do any serious programming. Python provides several ways to modularize the source code: Functions,

modules, packages and classes. This chapter covers all of them, with the exception of objects, that have their own chapter.