Where is CASE?????

Harry George hgg9140 at cola.ca.boeing.com
Tue Feb 20 09:56:37 EST 2001


No, but do you really need it?  First, if you do a performance
profiling, you will find if...elif...elif... is not so bad.  But it
isn't pretty either.  So consider using a map:

color_function={'red':do_red,'green':do_green,'blue':do_blue}
#get some case value in domain red,green,blue, then:
    ftn=color_function[value]
    ftn()

Or even:
    color_function[value]()

Further, this approach lends itself to dynamically defining and adding
cases, which can't be done with statically compiled CASE statements.
Thus registering new colors and their actions is a piece of cake.

"Chris Richard Adams" <chrisa at ASPATECH.COM.BR> writes:

> Someone please tell me why I cannot find a CASE statement in the Python
> documentation index...
> 
> There is a CASE isn't there???
> 

-- 
Harry George                E-mail:  harry.g.george at boeing.com
The Boeing Company          Renton:  (425) 237-6915
P. O. Box 3707  02-CA       Everett: (425) 266-3868
Seattle, WA 98124-2207      Page:    (425) 631-8803  



More information about the Python-list mailing list