this post was submitted on 28 Aug 2023
29 points (96.8% liked)

Python

6366 readers
4 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

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.

top 1 comments
sorted by: hot top controversial new old
[–] lascapi@jlai.lu 3 points 1 year ago

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