Another stab at a "switch/case" construct (for Python 3000):

Ken Peek Ken.Peek at Engineer.com
Sat Mar 30 14:07:37 EST 2002


Steven Majewski <sdm7g at Virginia.EDU> wrote in message news:<mailman.1017449771.10283.python-list at python.org>...
> On Fri, 29 Mar 2002, Bjorn Pettersen wrote:
> 
> > > From: Steve Lamb [mailto:grey at despair.dmiyu.org]
> > >
> > > its_called_a_directory_pointing_to_functions = {'case':closed}
> > >
> > >     I do not believe that any language which can have a hash
> > > of function pointers has any business with a case statement.
> >
> > But that only works when all the functions in all the branches take the
> > same number and types of arguments -- hardly the general case.
> >
> 
> table = {}
> 
> table[key] = func, (args,...)
> ...
> 
> def doit( k ):
> 	return table[k][0]( *table[k][1] )
> 
> 
> You could also use entries that are lists of (func,args) pairs,
> and there are ways of constructing nested tables.
> 
> 
> -- Steve Majewski


You could also write some nice (very readable!) assembly language
code, and add some wrappers to Python!  This would be a GREAT
alternative to adding standard constructs to Python!

sarcastically yours,
Ken Peek



More information about the Python-list mailing list