為什麼清單「spans」從未更新?我不明白為什麼程式碼會陷入無限循環。
pdf:https://www.sil.org/system/files/reapdata/62/99/18/62991811720566250411942290005522370655/40337_02.pdf
import fitz doc = fitz.open("cubeo/40337_02.pdf") page = doc[3] blocks = page.get_text("dict", flags = fitz.TEXTFLAGS_TEXT)["blocks"] for block in blocks: entries = [] if len(block["lines"]) > 3: # ignora legendas e número de página for line in block["lines"]: spans = [] for span in line["spans"]: spans.append({"text": span["text"].replace("�", " "), "size": int(span["size"]), "font": span["font"]}) # While there are spans left while True: # Delimits where an entry starts entry_first_position = None for i, span in enumerate(spans): if span["font"] == "Sb&cuSILCharis-Bold": entry_first_position = i break if entry_first_position is not None: # Delimits where an entry ends entry_last_position = None for i, span in enumerate(spans[entry_first_position:], start=entry_first_position): if span["font"] == "Sb&cuSILCharis-Bold": entry_last_position = i break if entry_last_position is not None: # Whole entry is added as a list append_list = spans[entry_first_position:entry_last_position] entries.append(append_list) spans = spans[:entry_first_position] + spans[entry_last_position:] else: break else: break print(spans)
for i, span in enumerate(spans[entry_first_position:], start=entry_first_position):
for i, span in enumerate(spans[entry_first_position+1:], start=entry_first_position+1):
以上是在 Python 中循環時更新列表時出錯的詳細內容。更多資訊請關注PHP中文網其他相關文章!