Vincent Davis <vinc...@vincentdavis.net> writes:

> In the code below try is used to check if handle has the attribute name. It
> seems an if statement could be used. Is there reason one way would be
> better than another?

The Python community refers to the difference by contrasting “look
before you leap” (LBYL) versus “easier to ask forgiveness than
permission” (EAFP), and tends to prefer the latter.

<URL:http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#eafp-vs-lbyl>

“It is easier to ask forgiveness than permission” is attributed to
computer programming legend Rear Admiral Grace Hopper (she who
documented the first actual computer bug — a large moth in the wires).

Alex Martelli explores when LBYL and EAFP are each appropriate in Python
<URL:http://pyvideo.org/video/1338/permission-or-forgiveness-0>.

-- 
 \       “The optimist thinks this is the best of all possible worlds. |
  `\           The pessimist fears it is true.” —J. Robert Oppenheimer |
_o__)                                                                  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to