Case Statements

Antoon Pardon antoon.pardon at rece.vub.ac.be
Wed Mar 16 05:35:16 EDT 2016


Op 16-03-16 om 09:47 schreef Mark Lawrence:
>
>>
>> Same with switch. You can use a hash table etc. to simulate switches,
>> but only if the codeblocks are independent. Otherwise, if-elif chains
>> are the way to go. Command line parsing is a case where switch
>> statements are often used, e.g. in shell scripts.
>
> I've seen at least six different ways of simulating switches, so those
> people who want them, can have them.  if-elif chains are not likely to
> kill any Python programmer.
>
> I have no interest what other languages use switch/case statements
> for, as we've on the PYTHON mailing list.

There once were multiple ways to simulate a conditional expression.
And it was generally thought that using if else statements instead
of a conditional expression was unlikely to kill any Python programmer.

But then one of the core developers was bitten by a nasty bug because
he was using one of those constructs that simulated a conditional
expression and soon enough Python had a conditional expression.

So I guess those who would like a case statement in Python can
only hope a core developer gets bitten by a nasty bug while using
one of those ways of simulating switches.

-- 
Antoon Pardon




More information about the Python-list mailing list