TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Python Enums for Humans

10 pointsby wusterabout 13 years ago
I've been doing Python web apps for a few years. All of them have involved some pattern of declaring runtime vars to represent DB values, and also mapping those DB values to user-facing display values in your view templates. The practice of keeping the { var --&#62; value } and { value --&#62; display string } maps separately led to annoying dev-time bugs. Here's my short and easy solution.<p>MIT License. Enjoy.

2 comments

stevekabout 13 years ago
Does nobody else find the repetition objectionable? e.g. NEW = ('N', 'New'), If your values have good names, you can easily deduce "Some Constant" from SOME_CONSTANT or vice-versa. While I'm at it, having abbreviations built-in seems iffy too.
评论 #3640618 未加载
jaspersfatherabout 13 years ago
What makes that better than just using strings?
评论 #3640600 未加载