Another stab at a "switch/case" construct (for Python 3000):
Steven Majewski
sdm7g at Virginia.EDU
Fri Mar 29 19:54:36 EST 2002
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
More information about the Python-list
mailing list