rights. 4¡¢the fourth is a smart reference that ¡°performs additional actions when an object is accessed¡±.We can use the same coding approach for all proxies, although the fourth use case¡¯s behavior could also be achieved using a descriptor """ # sample 1 # a virtual proxy that allows us to create lightweight objects instead of # heavyweight objects, only creating the heavyweight objects if they are actually # needed from PIL import Image as Image YELLOW, CYAN, BLUE, RED, BLACK = (Image.color_for_name(color) for color in ("yellow", "cyan", "blue", "red", "black")) class ImageProxy: def __init__(self, ImageClass, width=None, height=None, filename=None): assert (width is not None and height is not None) or filename is not None self.Image = ImageClass self.commands = [] if filename is not None: self.load(filename) else: self.commands = [(self.Image, width, height)] def load(self, filename): self.commands = [(self.Image, None, None, filename)]