Created
August 20, 2020 15:42
-
-
Save switowski/18cfcba35aac1337f75f9891bc6cd114 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: | |
hello = "world" | |
bar = "world" | |
baz = "world" | |
class Foo(BaseClass): | |
pass | |
FOO = Foo() | |
# Look before you leap | |
def test_lbyl2(): | |
if hasattr(FOO, "hello") and hasattr(FOO, "bar") and hasattr(FOO, "baz"): | |
FOO.hello | |
FOO.bar | |
FOO.baz | |
# Ask for forgiveness | |
def test_aff2(): | |
try: | |
FOO.hello | |
FOO.bar | |
FOO.baz | |
except AttributeError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment