Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106943

Re: Enum questions.

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: Enum questions.
Date 2016-04-13 17:07 +0300
Organization A noiseless patient Spider
Message-ID <878u0htxe5.fsf@elektro.pacujo.net> (permalink)
References <570E1B98.4080904@rece.vub.ac.be> <CAGgTfkPfcwamSgRFH9PwuVV4MGsnDwcZOD1=bS=7z+RWnEP0eg@mail.gmail.com> <nelir9$163$1@ger.gmane.org> <mailman.72.1460555456.15650.python-list@python.org>

Show all headers | View raw


Grant Edwards <grant.b.edwards@gmail.com>:

> On 2016-04-13, Michael Selik <michael.selik@gmail.com> wrote:
>> An Enum corresponds to "nominal" data that is coded as a number
>> simply for storage rather than meaning.
>
> FWIW, as an old Pascal programmer, I too would have been surprised
> that an "enum" is not ordinal and doesn't support a next/prev and
> iteration.
>
> As an old C programmer, not so much. :)

From the Pascal point of view, the "number for storage" seems odd. Why
not:

    class Color(enum.Enum):
        red = "red"
        blue = "blue"
        green = "green"

or:

    class Color(enum.Enum):
        red = object()
        blue = object()
        green = object()

or:

    class Color(enum.Enum):
        red
        blue
        green


This last one is to the point but raises a NameError.


Personally, I have not found enum.Enum all that appealing. If I have
needed such enums in my code, I have usually just defined:

    class MyClass:
        RED = "RED"
        BLUE = "BLUE"
        GREEN = "GREEN"
            

Marko

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Enum questions. Grant Edwards <grant.b.edwards@gmail.com> - 2016-04-13 13:50 +0000
  Re: Enum questions. Marko Rauhamaa <marko@pacujo.net> - 2016-04-13 17:07 +0300
    Re: Enum questions. Ethan Furman <ethan@stoneleaf.us> - 2016-04-13 07:21 -0700
    Re: Enum questions. Ethan Furman <ethan@stoneleaf.us> - 2016-04-13 14:13 -0700

csiph-web