Hey Pythonista,
Welcome back to our weekly newsletter. What do you think of our new format? Reply and let us know!
Here are a couple of Python | developer | Pybites nuggets, enjoy!
1) Not all duplicated code is bad. 💡
I’m a strong advocate for DRY (don’t repeat yourself) in my code and when reviewing others'.
However, while reading 99 Bottles of OOP (by Sandi Metz and Katrina Owen), I came across an elegant counterexample.
It embraced a bit of duplication (via match/case) but significantly improved:
Simplicity
Readability
Maintainability
It reminded me that in software, few rules are absolute. The right choice often depends on the codebase and its context.
Above all, prioritize simplicity and think about how easy it will be to adapt or extend your code in the future. 🚀
2) uv 😍 📈
Did you know you can easily try the free-threading Python 3.13 version using `uv run --python 3.13t`
Or what about trying out the latest Python 3.14 alpha? You can use: `uv python install 3.14 --preview`
Curious to hear who is not yet using uv?
Hear more from the creator of uv about what went into building this amazing tool
3) To walrus or not to walrus?
`:=` was introduced in 3.8 and it's a feature that can lead to very concise code, but also overly convoluted code.
A feature to hate to love, love to hate? I came across two nice use cases I shared on LinkedIn.
Check them out and join the discussion here: https://www.linkedin.com/feed/update/urn%3Ali%3Aactivity%3A7273287302854950913/
4) functools, another awesome Python Standard Library module 💎
Unlock the power of Python with the functools module and write more efficient, readable, and maintainable code 🤩
Ever heard of caching? Use the @cache decorator to speed up your computations. 🚀
Simplify your code with less dunder methods! @total_ordering can automate class comparisons, reducing boilerplate code. 📈
Freeze a part of your function using partial() creating 'reusable components'. 🎉
Handle multiple data types gracefully with @singledispatch for generic functions. 💡
Preserve function metadata while creating decorators is important. functools.wraps() has you covered. 🤝
Aggregate data smartly using reduce() for powerful data transformations.
Full article: https://pybit.es/articles/6-cool-things-you-can-do-with-the-functools-module/
5) The Pybites Platform now has tips!
We've written an incredible number of tips over the years which we've now integrated into the new Pybites Platform. And yes, they're categorised!
You can check these out, along with our 400+ Python exercises using the following link (must be logged in).
|