3 ms·
I am surprised to see a recommendation to use an exception handler for conditionals, especially for Python.
by magoon 11y ago
I am surprised to see a recommendation to use an exception handler for conditionals, especially for Python.
- lumpypua 11y agoEAFP is in the Python coding glossary: 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. http://stackoverflow.com/a/11360880/36092 http://stackoverflow.com/a/11360880/36092
- flooo 11y agoThis style using try/except instead of if/else is known as EAFP (Easier to Ask Forgiveness than Permission). It's actually recommended in the Python glossary [0]. [0] https://docs.python.org/3.5/glossary.html#term-eafp https://docs.python.org/3.5/glossary.html#term-eafp
- collyw 11y agoI though this style was encouraged in Python.