class box: def __init__(self): self.__dict__['center'] = [2,3] self.__dict__['size'] = [4,6] def __getattr__(self, name): if name in self.__dict__: return self.__dict__[name] cx,cy = self.center w,h = self.size if name == 'left': return cx-w/2 if name == 'right': return cx + w/2 if name == 'top': return cy - h/2 if name == 'bottom': return cy + h/2 if name in ('x','cx','centerx','xcenter'): return cx if name in ('y','cy','centery','ycenter'): return cy if name in ('w', 'width'): return w if name in ('h', 'height'): return h def __setattr__(self, name, value): if name in self.__dict__: self.__dict__[name] = value return cx,cy = self.center w,h = self.size if name == 'left': self.center[0] = value + w/2 elif name == 'right': self.center[0] = value - w/2 elif name == 'top': self.center[1] = value + h/2 elif name == 'bottom': self.center[1] = value - h/2 elif name in ('x','cx','centerx','xcenter'): self.center[0] = value elif name in ('y','cy','centery','ycenter'): self.center[1] = value elif name in ('w', 'width'): self.size[0] = value elif name in ('h', 'height'): self.size[1] = value else: print("WARNING: adding ."+name,'to box object') self.__dict__[name] = value def __str__(self): return '{}×{} box at ({},{})'.format(self.w,self.h,self.x,self.y) b = box() print(b) print(b.bottom) b.bottom = 100 print(b.bottom) print(b.top) print(b)