Book Image

Modular Programming with Python

By : Erik Westra
Book Image

Modular Programming with Python

By: Erik Westra

Overview of this book

Python has evolved over the years and has become the primary choice of developers in various fields. The purpose of this book is to help readers develop readable, reliable, and maintainable programs in Python. Starting with an introduction to the concept of modules and packages, this book shows how you can use these building blocks to organize a complex program into logical parts and make sure those parts are working correctly together. Using clearly written, real-world examples, this book demonstrates how you can use modular techniques to build better programs. A number of common modular programming patterns are covered, including divide-and-conquer, abstraction, encapsulation, wrappers and extensibility. You will also learn how to test your modules and packages, how to prepare your code for sharing with other people, and how to publish your modules and packages on GitHub and the Python Package Index so that other people can use them. Finally, you will learn how to use modular design techniques to be a more effective programmer.
Table of Contents (16 chapters)
Modular Programming with Python
About the Author
About the Reviewer

Implementing Charter

We know that the Charter library's public interface will consist of a number of functions accessed at the package level, for example charter.new_chart(). However, using the techniques covered in the previous chapter, we know that we don't have to define our library's API in the package initialization file to make these functions available at the package level. Instead, we can define the functions elsewhere, and import them into the file so that they are available for others to use.

Let's start by creating a directory to hold our charter package. Create a new directory named charter, and create within it an empty package initialization file, This gives us the basic framework within which to write our library:

Based on our design, we know that the process of generating a chart will involve the following three steps:

  1. Create a new chart by calling the new_chart() function.

  2. Define the contents and appearance of the chart by calling the various set_XXX...