-
-
Save digitalconceptvisuals/f39a4c4a2d28fb023783c3fae48cfa7a 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
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