Hi everyone!
I want to do the following: I have a container-class Container, it has attribute attr, which refers to another class OtherClass.
class OtherClass:
def __init__(self, value):
self._value = value
def default(self):
retirn self._value
def another(self):
return self._value ** 2
def as_str(self):
return 'String: %s' % self._value
class Container:
def __init__(self, attr):
self.attr = OtherClass(attr)
I want to:
x = Container(2)
x.attr # when accessing the attribute - return value from default method
2
x.attr.another() # but also an attribute can be treated as an object
4
x.attr.as_str()
'String: 2'
How can I do this?