讨论数量:
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