Enumming
Ken Kinder
kkinder at tridog.com
Mon Aug 21 16:41:13 EDT 2000
There are two schools of thought I've usually seen, yours being the forth.
I've seen a lot of code like this (I'll pick image types for the enum):
GIF = 1
JPEG = 2
PNG = 3
imagetype = GIF
For a larger program or an API, I would spin off all those constants
(constants by convention, not enforcement) into a module, so you would do
something like
import imagedefs
imagetype = imagedefs.GIF
The other school of thought is to just use strings
imagetype = 'GIF'
Personally, your system of
GIF, PNG, JPEG = range(3)
seems very reasonable to me.
Larry Whitley wrote:
> I come to Python from C++ and am wondering how Pythoners do the equivalent
> of the C++ enum. My current approach is to have an enum class with some
> constants in it for use with my regular class. It there something more
> clever that I've missed?
>
> Let's say I have a list of tuples like so:
>
> myList = []
> for i in range( 10 ):
> myList.append( functionA(), funcationB(), functionC(), functionD(),
> functionE() )
>
> Here's my class of enums:
>
> class E:
> a,b,c,d,e = range( 5 )
>
> Later, I use the enums to access my list:
>
> myC = myList[5][ E.c]
>
> Is this the usual approach?
>
> Larry
>
> --
> http://www.python.org/mailman/listinfo/python-list
--
Ken Kinder
Staff Engineer - Tridog Interactive, Inc.
kkinder at tridog.com
http://www.tridog.com/ - 303-415-2538
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kkinder.vcf
Type: text/x-vcard
Size: 257 bytes
Desc: Card for Ken Kinder
URL: <http://mail.python.org/pipermail/python-list/attachments/20000821/5ccd61ff/attachment.vcf>
More information about the Python-list
mailing list