4 ms·
I was convinced this statement was also in the "Zen of Python" (PEP 20 [0]), but it's "only" in the official glossary [1] > EAFP > Easier to ask for forgive
by afraca 8y ago
I was convinced this statement was also in the "Zen of Python" (PEP 20 [0]), but it's "only" in the official glossary [1]
> EAFP
> Easier to ask for forgiveness than permission. This common Python coding style assumes the
existence of valid keys or attributes and catches exceptions if the assumption proves false.
This clean and fast style is characterized by the presence of many try and except statements.
The technique contrasts with the LBYL style common to many other languages such as C.
edit: Sorry to bring programming to the table again, the 'philosophical' side is also interesting of course!
[0]: https://www.python.org/dev/peps/pep-0020/ https://www.python.org/dev/peps/pep-0020/
[1]: https://docs.python.org/3/glossary.html https://docs.python.org/3/glossary.html