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

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Sat Mar 30 08:35:49 EST 2002


Steven Majewski <sdm7g at Virginia.EDU> wrote:

>
>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.
>
>
There are many ways of achieving the same result as a nice clear
case/switch/whatever construct, but they all end up being an exercise
in deduction for the reader.

You can't beat a properly designed construct for the purpose. Then, at
least, everyone knows what you're trying to achieve.
--
Dale Strickland-Clark
Riverhall Systems Ltd



More information about the Python-list mailing list