class Screen(object): @property def width(self): return self.__width @width.setter def width(self, value): if not isinstance(value, (int, float)): raise TypeError('Width Error Value Type, Not int or float') self.__width = value @property def height(self): return self.__height @height.setter def height(self, value): if not isinstance(value, (int, float)): raise TypeError('Height Error Value Type, Not int or float') self.__height = value @property def resolution(self): return self.height * self.width def __str__(self): str = super().__str__() return '%s, width:%.1f, height:%.1f, resolution:%.1f' % (str, self.width, self.height, self.resolution)
# test screen = Screen() screen.height = 768 screen.width = 1024 print(screen)
Sign in to make a reply
gitKong