News for hackers. Stuff that matters.
Re:Why People Should Learn Python by mertd on Wednesday August 24, 2016 @07:02AM (#12351091)
#2 is because it is more "pythonic" to ask for forgiveness than permission (EAFP).

For example, rather than checking if a dictionary has an element before accessing it, you just try to access it and handle the KeyError if it doesn't. The code reads easier and the normal flow would be faster in this case.

When used in EAFP context only, I think it is fine to use exceptions as part of logic in Python. They are relatively less costly compared to C.

There are no comments on this comment yet.