A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-November/105928.html below:

[Python-Dev] constant/enum type in stdlib

[Python-Dev] constant/enum type in stdlibSteven D'Aprano steve at pearwood.info
Tue Nov 23 22:30:37 CET 2010
Antoine Pitrou wrote:

> Python already has an enumeration capability. It's called range().
> There's nothing else that C enums have. AFAICT, neither do enums in
> other mainstream languages (assuming they even exist; I don't remember
> Perl, PHP or Javascript having anything like that, but perhaps I'm
> mistaken).


In Pascal, enumerations are a type, and the value of the named values 
are an implementation detail. E.g. one would define an enumerated type:

type
   flavour = (sweet, salty, sour, bitter, umame);
var
   x: flavour;

and then you would write something like:

x := sour;

Notice that the constants sweet etc. aren't explicitly predefined, since 
they're purely internal details and the compiler is allowed to number 
them any way it likes. In Python, we would need stronger guarantees 
about the values chosen, so that they could be exposed to external 
modules, pickled, etc.

But that doesn't mean we should be forced to specify the values ourselves.


-- 
Steven

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4