class DocxProcessor: def __init__(self): self.current_img_idx = 0 def replacer(self, match): if self.current_img_idx < len(self.listImage): result = f'' self.current_img_idx += 1 return result return match.group()