Let us have an example class Foo in Python:
class Foo:
bar = 'bar'
def access_bar(self):
return self.bar
Can I, for example print a warning, when accessing Foo().bar
directly, but at the same time not print this warning when calling Foo().access_bar()
, which accesses that attribute from within the class?
I tried to implement __getattribute__
method, but with no luck with differentiating these cases.
I know it's quite a strange question, but please don't answer me like 'You should not need this'.