one more thing Re: Enumming
Ken Kinder
kkinder at tridog.com
Mon Aug 21 16:44:19 EDT 2000
One more thing. In cases where it's coming in from a database or a file, or
something, I usually like to make a mapping in the form of a dictionary
imagetypes = {
'GIF':1,
'JPEG':2
}
and the mapping changes as your schema changes. Sometimes a reverse-table is
also nice. Making those is easy.
reverse_imagetypes
for key in imagetypes.keys():
value = imagetypes[key]
reverse_imagetypes[value] = key
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/b516fc03/attachment.vcf>
More information about the Python-list
mailing list