this post was submitted on 29 Aug 2023
33 points (100.0% liked)

Python

6288 readers
6 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
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 6 points 1 year ago (2 children)

To be honest, for me it looks as very strange pattern.. If one wants to have static container with functions, there is Enums or classes.

[–] Walnut356 2 points 1 year ago

It's most useful when you're using some data you already have as the dictionary key. A usecase i had for this was a binary file parser with 10 types of event markers. It was originally coded with if/elif, but performance was a pretty big consideration. Using the event markers as keys to a dictionary dispatch improved performance by about 15% and made the code significantly more readable.

[–] [email protected] 1 points 1 year ago

With classes you needs getattr in python to achieve the same. This is cleaner for simple mappings