Chapter 4 Avoiding Traps

Intuitive Python — by David Muller (30 / 41)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Wrapping Up | TOC | Serializing Python Objects with the pickle Mo dule 👉

Many of my favorite foods are junk foods: ice cream, Oreos with milk, Nutter Butters, chocolate chip cookies, and the like. If my pantry has any of these foods in it, I will eat them — enjoying a glass of milk and Oreos is a simple pleasure that I’ve indulged in more than my fair share of times.

Being gluttonous is fun sometimes, but staying in shape and healthy are also important to me. One time I ate a whole bag of Oreos and couldn’t stomach much else for the next few days. So, I have to strike a balance to avoid trapping myself in a situation where I might eat too many Oreos. Since I know that I’ll eat any delicious junk food that gets into my house, I have to stop the problem at the source. I can’t ever buy any junk food, because then I know I am guaranteed to eat it.

In a similar way, Python has its own share of junk food. Delicious parts of the standard library that, if used too much, can trap your Python project in an unhealthy situation. To keep a Python project in check, we must be diligent to avoid falling into traps that might hurt us.

You’ve already encountered and used important parts of standard library including — most recently — tools for concurrency. In this chapter, though, you will focus on the dangers of the pickle module, datetime objects without timezones, and mutable default function arguments…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.