Created
August 20, 2020 15:43
-
-
Save switowski/f74b72905793f631c0e6b0ce2237dce8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# permission_vs_forgiveness.py | |
class BaseClass: | |
pass # "hello" attribute is now removed | |
class Foo(BaseClass): | |
pass | |
FOO = Foo() | |
# Look before you leap | |
def test_lbyl3(): | |
if hasattr(FOO, "hello"): | |
FOO.hello | |
# Ask for forgiveness | |
def test_aff3(): | |
try: | |
FOO.hello | |
except AttributeError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment