[Tutor] enumeration in C++
alan.gauld@bt.com
alan.gauld@bt.com
Mon, 1 Apr 2002 23:47:13 +0100
> 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 just want a finite set of values then you
can use a tuple.
If you want to set a range of non contiguous values to
a collection of names then I think you need a
dictionary - but then it becomes mutable! Of course
you could use a tuple of single element dicionaries,
but thats not bombproof either!
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! :-)
For most enum things in C++ there is a different
idiom in Python - what aspect took your fancy?
Alan G