[Python-Dev] constant/enum type in stdlib

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Nov 24 00:32:56 CET 2010


Bill Janssen wrote:

> The main purpose of that is to be able to catch type mismatches with
> static typing, though.  Seems kind of pointless for Python.

But catching type mismatches with dynamic typing doesn't
seem pointless for Python. There's nothing static about
the proposals being made here that I can see.

> Why not
> 
>   class Color:
>      red = (255, 0, 0)
>      green = (0, 255, 0)
>      blue = (0, 0, 255)

If all you want is a bunch of named constants, that's fine.
But the facilities being discussed here are designed to give
you other things as well, such as

   c = Color.red
   print(c)

printing "red" rather than "(255, 0, 0)".

-- 
Greg


More information about the Python-Dev mailing list