Introduction One cool object-oriented programming (OOP) technique / pattern is enforcing consistent interfaces. In Python you can use Abstract Base Classes (ABCs) for that. 🐍 Using ABCs ensures that all subclasses implement the required methods. This can make it easier to maintain and extend the existing code base. Update Feb 2024: you can also leverage… Continue reading Elevate Your Python: Harnessing the Power of Abstract Base Classes (ABCs)
Articles on contextlib
What The Heck Is Yield For?
By Erik O'Shaughnessy on 11 October 2023
A question came up recently about the purpose of the Python yield expression and when you should use it. Consider this silly function that computes a list of integers from 0 to 99 raised to the given exponent: When called, this function runs thru all 100 integers in the range computing each term and then returns the… Continue reading What The Heck Is Yield For?
Avoiding Silent Failures in Python: Best Practices for Error Handling
By Bob Belderbos on 7 August 2023
In the world of programming, errors are inevitable. But how we choose to handle these errors can make the difference between a system that is robust and user-friendly and one that is fraught with ambiguous issues 😱 The Zen of Python famously states, “Errors should never pass silently.” This principle emphasizes the importance of addressing… Continue reading Avoiding Silent Failures in Python: Best Practices for Error Handling
Code Challenge 09 – The With Statement and Context Managers
By PyBites Team on 6 March 2017
A new week, more coding! This week we have a free form exercise. This week you will implement your own Context Manager (= support with on your object).