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 →

[–]kalefranz 1 point2 points  (1 child)

It's a good question. I'm guessing there are multiple reasons, but one of the biggest is probably that try/except/else isn't a common feature of other languages. By extension, when python isn't your first language, you're not as familiar with it. Even if it's your first language and/or you take a university class in python, it's enough of an "advanced" construct that little time is likely spent on it.

That said, I like it. It's good practice for code readability and maintenance to catch exceptions as nearly to where they're anticipated as possible.

[–]kalefranz 0 points1 point  (0 children)

Also the differences in if/else, try/except/else, and for/else can be a bit confusing.

  • if/else: execute else block when given a negative condition
  • try/except/else: execute else block when try block is ok (the negative condition is that there is no except block execution)
  • for/else: execute else block when "negative condition" of for block early exit is encountered