If you're coming from a compiled language context, using exceptions for flow control would look odd to you. But here's the thing - in the python world, exceptions are super cheap and using them for flow control is the "idiomatic python" way!
In fact, exception-driven flow control is built right into the language itself e.g. the "for" loop in python terminates when the iterable raise a "StopIteration" exception!
There is a lot of material on the internet already on the topic, so if there's one thing you take out of this post, it's this - in python, it's "Easier to Ask for Forgiveness than Permission"!
In fact, exception-driven flow control is built right into the language itself e.g. the "for" loop in python terminates when the iterable raise a "StopIteration" exception!
There is a lot of material on the internet already on the topic, so if there's one thing you take out of this post, it's this - in python, it's "Easier to Ask for Forgiveness than Permission"!
Comments
Post a Comment