a 'case' statement?

Chad Netzer cnetzer at mail.arc.nasa.gov
Fri Feb 14 06:02:51 CET 2003


On Thu, 2003-02-13 at 20:47, Wouter van Marle wrote:
> Hi!
> 
> I miss something like Pascal's case: statement! (probably my Pascal syntax
> is not correct, it's too long ago, it was a very very handy one anyway!)
> 
> case keyword is:
> 'life':
>    killit()
> 'dead':
>    buryit()
> else:
>   donothing()
> end

call_table = { 'life' : killit, 'dead' : buryit }
f = call_table.get( keyword, donothing )
f()

> In Python I have to do this with the not so nice if, elif, else statements.

You don't HAVE to...

-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
(any opinion expressed is my own and not NASA's or my employer's)







More information about the Python-list mailing list