Skip to content

Instantly share code, notes, and snippets.

@digitalconceptvisuals
Created July 30, 2020 20:49
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 digitalconceptvisuals/f39a4c4a2d28fb023783c3fae48cfa7a to your computer and use it in GitHub Desktop.
Save digitalconceptvisuals/f39a4c4a2d28fb023783c3fae48cfa7a to your computer and use it in GitHub Desktop.
class Univ:
def __init__(self):
self.name = "ABC"
# This gets called when attribute is missing
def __getattr__(self, attribute):
try:
return self[attribute]
except:
return "We are very sorry, we cannot server you that yet"
univ = Univ()
print(univ.name) # Actual attribute
print(univ.college) # Custom response
''' Output
ABC
We are very sorry, we cannot server you that yet
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment