Where is CASE?????

Lance.Ellinghaus at eConnections.com Lance.Ellinghaus at eConnections.com
Tue Feb 27 20:26:04 CET 2001


This can be done using a dictionary and functions pretty easily. At least
that is how I have always done it. For example...

def func_a():
     pass

def func_b():
     pass

def func_c():
     pass

func_dict = {
     'A': func_a,
     'B': func_b,
     'C': func_c
     }

try:
     apply(func_dict[test_value], ())
except:
     print '%c is not a valid choice' % test_value


This works for any type of value in 'test_value' and is pretty fast
executing.


--
Lance Ellinghaus
Phone: 940-466-7251
Pager: 800-226-4526 or lellinghaus at bellsouthips.com
Sr. Architect - eConnections, Inc.



                                                                                                                                      
                    Norman Shelley                                                                                                    
                    <Norman_Shelley-RRDN60 at email.sp        To:     python-list at python.org                                             
                    s.mot.com>                             cc:                                                                        
                    Sent by:                               Subject:     Re: Where is CASE?????                                        
                    python-list-admin at python.org                                                                                      
                                                                                                                                      
                                                                                                                                      
                    02/27/01 12:55 PM                                                                                                 
                                                                                                                                      
                                                                                                                                      




This argument is similiar to Bertrand Meyer's argument for not having a
CASE statement in early versions of Eiffel.  He finally "saw the light"
and added in the CASE statement.  I believe he finally saw the need to
efficiently be able to handle character and string data (real world data
that has not yet been objectized).



Larry Smith wrote:

> ...
>
> However, in Guido's defense, I will also point out the
> primary use of case statements is to select alternatives
> based on a type flag - which is not needed in an object
> oriented language.
>
> --
>  .-.    .-. .---. .---. .-..-. | Do not mistake  my cynicism
>  | |__ / | \| |-< | |-<  >  /  | for dispair for deep inside
>  `----'`-^-'`-'`-'`-'`-' `-'   | me is an  optimist  forever
>   http://www.smith-house.org/  | asking, "Why not?"

--
http://mail.python.org/mailman/listinfo/python-list








More information about the Python-list mailing list