In this video, we adapt a clumsy, non-Pythonic API into an easy to use, easy to understand Pythonic one. We use magic methods such as getitem_, len, enter, and _exit to make our objects a context manager and support the len() function and square bracket indexing. And in the end, we turn what once was ugly, difficult to maintain code into something that other developers would actually want to use.

  • @lascapi
    link
    410 months ago

    Nice to see how to improve python code like that! I love that the __getitem__ and __len__ made the object iterable ! 🤩