Hi Ram,

I use enum in my code from time to time, based on a class I wrote, which in
turn is based on several recipes I saw and my ideas on how it should look.
I guess the reason people use string or number constants is because it's
easier, one less dependency and not that important.
Furthermore, in my code, even when I have my class or a recipe available,
sometimes it's just "not worth it" for something very small and simple.

Cheers,
Imri

P.S.
Back when I wrote the class I use I also wrote something about it in my
blog, you can see it here
http://www.algorithm.co.il/blogs/programming/various-small-python-helpers/


On Thu, Jun 9, 2011 at 8:06 PM, cool-RR <[email protected]> wrote:

> Hello all,
>
> A while ago I was introduced to the concept of 
> enum<http://en.wikipedia.org/wiki/Enumerated_type>in Java. I never programmed 
> Java, but this looks like
> *the* solution for when you want a variable to hold a value from a limited
> set of possible values. What is usually done in Python is either using a
> string or an index number, both of which are less elegant solutions in my
> opinion.
>
> Python doesn't provide a built-in enum type, but I found a few third-party
> modules, out of which I chose `flufl.enum` as being the most promising:
>
> http://packages.python.org/flufl.enum/docs/using.html#creating-an-enum
>
> This looks like a pretty good solution. A tad less native than in Java, but
> still much better than strings or ints.
>
> My question is, why do I never see Python code that uses `flufl.enum`, or
> any other enum package for that matter? Is there some reason not to use
> enums in Python? Perhaps a large portion of Python programmers are ignorant
> about enums, (as I was before I saw it recently?) Or perhaps people just
> don't really care about making their code elegant?
>
> Anyway I'll try to start using `flufl.enum` soon. One awesome application
> that this could have is to make a Django `EnumField` (or `ChoiceField` or
> whatever you want to call it) instead of the current ugly way of making an
> `IntegerField` and defining `CHOICES` separately.
>
>
> Ram.
>
> _______________________________________________
> Python-il mailing list
> [email protected]
> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
>
>


-- 
Imri Goldberg
--------------------------------------
http://plnnr.com/ - automatic trip planning
http://www.algorithm.co.il/blogs/
--------------------------------------
-- insert signature here ----
_______________________________________________
Python-il mailing list
[email protected]
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

לענות