Skip to content

Instantly share code, notes, and snippets.

@switowski
Created August 20, 2020 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save switowski/18cfcba35aac1337f75f9891bc6cd114 to your computer and use it in GitHub Desktop.
Save switowski/18cfcba35aac1337f75f9891bc6cd114 to your computer and use it in GitHub Desktop.
# 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