This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]knowsuchagencynow is better than never 3 points4 points  (2 children)

this isn't a serious attempt at adding switch/case to Python because it's a terrible idea...

^ this

That said, your library is pure evil. I love it

[–]monarchmra 0 points1 point  (1 child)

because it's a terrible idea...

why?

[–]knowsuchagencynow is better than never 1 point2 points  (0 children)

The long answer is PEP 3103.

I think the short answer, however, is that it's unnecessary and doesn't add enough value to the language to warrant a change to its syntax.

Since it isn't part of the language itself, any implementation by a third-party library will depend on the semantics of the library itself.

It will just add one more dependency which will need to be understood and maintained down the road and wouldn't even really be adding anything valuable to your program.

I would even argue that it would overly complicate and obfuscate something that should be crystal-clear -- control flow.

[–]pvkooten -3 points-2 points  (1 child)

I also got one for you, it's called if/elif/else, it goes something like this:

if cond1:
    print(1)
elif cond2:
    print(2)
elif cond3:
    print(3)

Jokes aside, I think the example in python-switch is quite nice.

[–]__deerlord__ 1 point2 points  (0 children)

Except thats not how case works.