class Connection (Element) : def __init__ (self, structure) : super().__init__(structure) self.structure.connections.append(self) self._weights = Matrix() def __iter__ (self) : return iter(self._weights) def __repr__ (self, *args, **kw) : width = self._weights.width() height = self._weights.height() # A mock "dimensions" object for the textual representation. dimensions = type('Dimensions', (), {'__repr__' : lambda self : '{}x{}'.format(width, height)})() return super().__repr__(dimensions, *args, **kw) @property def weights (self) : return self._weights
def __init__ (self, structure) : super().__init__(structure) self.structure.connections.append(self) self._weights = Matrix()