[Tutor] enumeration in C++

dman dman@dman.ddts.net
Mon, 1 Apr 2002 18:28:44 -0600


On Mon, Apr 01, 2002 at 11:47:13PM +0100, alan.gauld@bt.com wrote:
| > Currently in college right now, I have come across 
| > enumeration in C++ and wanted to know if Python can 
| > do the same thing and how?
| 
| Depends on which bit of C++ enums you want to use, 
| its a flexible beast and gets used for all sorts 
| of tricks.
 
| If you need an autoincrementing list of consts 
| (eg error codes) then I think you might be beat 
| - ie I can't think of a pythonic equivalent! :-)

The value of a label in an enum is undefined (at least in C).  The
compiler _probably_ just starts at 0 and works its way up except for
the cases where you've specified the value, but it isn't guaranteed to
be that way.  In python you can use range() to assign increasing ints
to a set of names, but like most things pythonic you must be
disciplined enough not to reassign them later.

HTH,
-D

-- 

Consider what God has done:
    Who can straighten what He has made crooked?
        Ecclesiastes 7:13