Debugging with "format".format_map(vars())
One of the most important debugging and design tools available in Python is the print()
function. There are some kinds of formatting options available; we looked at these in the Using features of the print() function recipe.
What if we want more flexible output? We have more flexibility with the "string".format_map()
method. This isn't all. We can couple this with the vars()
function to create something that often leads to a wow!
Getting ready
Let's look at a multistep process that involves some moderately complex calculations. We'll compute the mean and standard deviation of some sample data. Given these values, we'll locate all items that are more than one standard deviation above the mean:
>>> import statistics
>>> size = [2353, 2889, 2195, 3094,
... 725, 1099, 690, 1207, 926,
... 758, 615, 521, 1320]
>>> mean_size = statistics.mean(size)
>>> std_size = statistics.stdev(size)
>>> sig1 = round(mean_size...