Answers for "python __getattr__ geeksforgeeks"

0

python __getattr__ geeksforgeeks

class Foo(object):
    def __init__(self):
        self.bar = "bar attribute"

    def __getattr__(self, attr):
        return attr.upper()

foo = Foo()
print(foo.bar)	# Output: bar attribute
print(foo.another_no_exist_attribute) # Output: ANOTHER_NO_EXIST_ATTRIBUTE
print(foo.itworks) # Output: ITWORKS
Posted by: Guest on September-18-2020

Python Answers by Framework

Browse Popular Code Answers by Language