"To samo, ale z ogólnym przechwytywaniem niezdefiniowanego atrybutu __getattr__ "

class Powers:
    def __init__(self, square, cube):
        self._square = square
        self._cube   = cube

    def __getattr__(self, name):
        if name == 'square':
            return self._square ** 2
        elif name == 'cube':
            return self._cube ** 3
        else:
            raise TypeError('nieznany atrybut:' + name)

    def __setattr__(self, name, value):
        if name == 'square':
            self.__dict__['_square'] = value             # Lub użyj object
        else:
            self.__dict__[name] = value

