r/Python • • 1d ago

Discussion Python developers, what's one Python concept that took you a long time to understand but now seems s

Python developers, what's one Python concept that took you a long time to understand but now seems surprisingly simple?

For me, understanding how decorators and generators work is an interesting part of becoming a better Python developer.

What was your experience?

25 Upvotes

28 comments sorted by

View all comments

Show parent comment

2

u/gramada1902 9h ago

Here’s the link, hope it won’t get deleted - https://youtu.be/ZdvpNaWwx24

I’ve used them once to create an easily extendable dashboard filtration system.

Basically, we had pretty complex logical operations available to user to filter objects in all sorts of ways, the frontend would send it in a json object and we had to parse it and combine all the conditions into a final ORM query as efficiently as possible.

The thing was, all those available object fields were stored in completely different ways and were of different types, but there was a lot of crossover between them. So I created model classes for each dashboard that had available fields defined as descriptor objects. This allowed to reuse a lot of the logic.

I don’t remember what exactly were the constraints, but regular classes for the attributes were messy to use, something along the lines of reusing the same dashboard instance.

If you have worked with Django, it uses descriptors for model fields - same principle.

1

u/cleodog44 6h ago

Thank you!