O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling errors and exceptions

Python follows the EAFP (short for easier to ask for forgiveness than permission) style of coding as opposed to the LBYL (look before you leap) style that is followed by most programming languages.

Therefore, handling exceptions in a way that is similar to the following one is normally cleaner in Python than checking conditions using the if-then block.

So when coding in Python, rather than using the following style in coding:

if some_thing_wrong:  do_something_else()else:  do_something_normal()

Consider using this instead:

try:  do_some_thing_normal()except some_thing_wrong:  do_some_thing_else()

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required