python getattr geeksforgeeks

Solutions on MaxInterview for python getattr geeksforgeeks by the best coders in the world

showing results for - "python getattr geeksforgeeks"
Gemma
27 Jul 2017
1class Foo(object):
2    def __init__(self):
3        self.bar = "bar attribute"
4
5    def __getattr__(self, attr):
6        return attr.upper()
7
8foo = Foo()
9print(foo.bar)	# Output: bar attribute
10print(foo.another_no_exist_attribute) # Output: ANOTHER_NO_EXIST_ATTRIBUTE
11print(foo.itworks) # Output: ITWORKS