Skip to content

Instantly share code, notes, and snippets.

@switowski
Created August 20, 2020 15:43
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/f74b72905793f631c0e6b0ce2237dce8 to your computer and use it in GitHub Desktop.
Save switowski/f74b72905793f631c0e6b0ce2237dce8 to your computer and use it in GitHub Desktop.
# 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