Possible Duplicate:
Python try-else
Comming from a Java background, I don’t quite get what the else clause is good for.
According to the docs
It is useful for code that must be
executed if the try clause does not
raise an exception.
But why not put the code after the try block? It seems im missing something important here…
The
elseclause is useful specifically because you then know that the code in thetrysuite was successful. For instance:You can perform operations on
fsafely, because you know that its assignment succeeded. If the code was simply after the try … except, you may not have anf.