Python allows you to create enumerations that are also regular strings!
Previously, when working with APIs, JSON, and configurations, it was often necessary to manually extract the value from an Enum.
For example:
When serializing, you would get an enumeration object:
rather than a regular string:
In Python 3.11,
Now, the value can be used wherever a string is expected:
The result:
At the same time, the advantages of enumerations are preserved:
You cannot accidentally pass an incorrect value:
will result in an error.
🔥
#Python #Coding #StrEnum #DevTips #Programming #Python311
✨ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk
⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Previously, when working with APIs, JSON, and configurations, it was often necessary to manually extract the value from an Enum.
For example:
class Status(Enum):
ACTIVE = "active"
When serializing, you would get an enumeration object:
Status.ACTIVErather than a regular string:
"active"In Python 3.11,
StrEnum was introduced to solve this problem.from enum import StrEnum
class Status(StrEnum):
ACTIVE = "active"
BLOCKED = "blocked"
Now, the value can be used wherever a string is expected:
json.dumps({"status": Status.ACTIVE})The result:
{"status": "active"}At the same time, the advantages of enumerations are preserved:
Status.ACTIVEStatus.BLOCKEDYou cannot accidentally pass an incorrect value:
Status("unknown")will result in an error.
🔥
StrEnum allows you to combine the strict typing of enumerations with the convenience of regular strings, without manual conversion when working with APIs, JSON, and configurations.#Python #Coding #StrEnum #DevTips #Programming #Python311
✨ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk
⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
❤3
Your AI assistant is guessing because it doesn't know your documents.
Build a private AI workflow over your own PDFs and documentation:
• choose a model that fits your RAM or VRAM
• index your files locally
• require answers with source citations
• test the workflow in Python before adding agents
How AI Helps publishes practical local-AI setups, failure cases and a free model picker — tested workflows, not recycled AI news.
👉 Join How AI Helps
Build a private AI workflow over your own PDFs and documentation:
• choose a model that fits your RAM or VRAM
• index your files locally
• require answers with source citations
• test the workflow in Python before adding agents
How AI Helps publishes practical local-AI setups, failure cases and a free model picker — tested workflows, not recycled AI news.
👉 Join How AI Helps
❤1
Forwarded from Machine Learning with Python
This channels is for Programmers, Coders, Software Engineers.
0️⃣ Python
1️⃣ Data Science
2️⃣ Machine Learning
3️⃣ Data Visualization
4️⃣ Artificial Intelligence
5️⃣ Data Analysis
6️⃣ Statistics
7️⃣ Deep Learning
8️⃣ programming Languages
✅ https://t.me/addlist/8_rRW2scgfRhOTc0
✅ https://t.me/Codeprogrammer
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1