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 to support. For example, did you know that three teaspoons of sugar equals one tablespoon of sugar? To handle these types of conversions, let's write a unit conversion library.
Our unit converter will have to be aware of all the standard units used in...