讨论数量:
You cannot delete a paragraph by following statement because paragraph
is a new list created by docx, not the paragraph in the document.
del paragraph[10]
Do it by
def delete_paragraph(paragraph):
p = paragraph._element
p.getparent().remove(p)
p._p = p._element = None
if len(paragraph) > 10:
try:
delete_paragraph(paragraph[10])
paragraph = doc.paragraphs
print(f"Length after deleted:{len(paragraph)}")
except ValueError as e:
print("Error:{e}")
else:
print("The length of paragraph is less than 11 !")
You cannot delete a paragraph by following statement because
paragraph
is a new list created by docx, not the paragraph in the document.Do it by