Where is CASE?????

Emile van Sebille emile at fenx.com
Tue Feb 20 09:20:17 EST 2001


Or you may consider wrapping it in a dictionary:

Type "copyright", "credits" or "license" for more
information.
IDLE 0.6 -- press F1 for help
>>> def caseA(*args):
 print "CaseA ", args


>>> def caseB(*args):
 print "CaseB ", args


>>> def caseOther(*args):
 print "CaseOther ", args


>>> switch = {'A':caseA, 'B':caseB}
>>> switch.get('A',caseOther)
<function caseA at 0103153C>
>>> switch.get('A',caseOther)(1,2,3)
CaseA  (1, 2, 3)
>>> switch.get('B',caseOther)(1,2,3)
CaseB  (1, 2, 3)
>>> switch.get('C',caseOther)(1,2,3)
CaseOther  (1, 2, 3)
>>>

--

Emile van Sebille
emile at fenx.com
-------------------


"Steve Purcell" <stephen_purcell at yahoo.com> wrote in message
news:mailman.982676904.20104.python-list at python.org...
> Chris Richard Adams wrote:
> > Someone please tell me why I cannot find a CASE
statement in the Python
> > documentation index...
>
> Because there isn't one.
>
> Use if/elif/else instead.
>
> It doesn't sting as much as you might expect.
>
> -Steve
>
> --
> Steve Purcell, Pythangelist
> Get testing at http://pyunit.sourceforge.net/
> Get servlets at http://pyserv.sourceforge.net/
> "Even snakes are afraid of snakes." -- Steven Wright
>





More information about the Python-list mailing list