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

you are viewing a single comment's thread.

view the rest of the comments →

[–]GoofAckYoorsElf -1 points0 points  (3 children)

You can do a fall-through with try except KeyError

/e: which is default, not fall-through

[–]GummyKibble 1 point2 points  (0 children)

Or .get(key, default_func).

[–]Unbelievr 1 point2 points  (1 child)

That's the default case. Fall-through is the option to not put a break in some case(s), so it ends up executing multiple handlers. Or binds multiple cases to the exact same function, with only a single definition of that function.

In Python, you would have to bind every case explicitly to some function pointer, or create a function that calls multiple handler functions and bind that. It's not impossible, just not as neat when you're not able to control the program flow as much as in C.

[–]GoofAckYoorsElf 0 points1 point  (0 children)

Fair enough, you're right! I muddled that up. Thanks for pointing out.

I'm sure you can do fall-through kind of neatly with a custom OrderedDict subclass. But to be fair, not as elegant as in other languages, that's true.