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()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.91.254