[Python-Dev] constant/enum type in stdlib

Steven D'Aprano steve at pearwood.info
Tue Nov 23 22:06:45 CET 2010


Antoine Pitrou wrote:

> Constants = make_constants('Constants', 'SOME_CONST OTHER_CONST',   
>                            values=range(1, 3))
> 
> Again, auto-enumeration is useless since it's trivial to achieve
> explicitly.

That doesn't make auto-enumeration "useless". Unnecessary, perhaps, but 
not useless.

But even then it's only unnecessary if the number of constants are small 
enough that you can see how many there are without counting 
(essentially, 4 or fewer). When you have more, it becomes error-prone 
and a nuisance to have to count them by hand:

Constants = make_constants(
     'Constants',
     'ST_MODE ST_INO ST_DEV ST_NLINK ST_UID ST_GID' \
     'ST_SIZE ST_ATIME ST_MTIME ST_CTIME',
     values=range(10)
     )


-- 
Steven


More information about the Python-Dev mailing list