Designing a reusable package

Let's now take what we've learned and apply it to the design and implementation of a useful Python package. In the previous chapter, we looked at the concept of encapsulating a recipe using a Python module. Part of each recipe is the notion of an ingredient, which has three parts:

  • The name of the ingredient
  • How much of the ingredient is needed
  • The units in which the ingredient is measured

If we want to work with ingredients, we need to be able to handle units properly. For example, adding 1.5 kilograms to 750 grams involves more than adding the numbers 1.5 and 750—you have to know how to convert these values from one unit to another.

In the case of recipes, there are a number of rather unusual conversions that you need ...

Get Modular Programming with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.