1
程序在文档中创建一个标题(当前日期),如果该标题已经在文档中,我想避免标题可能出现重复。我的代码创建一个标题,但也重复。我应该在代码中更改该程序避免重复的内容?如何避免python-docx中的重复?
date = datetime.today().strftime('%A, %d. %B %Y')
document = Document('example.docx')
def duplicate(document):
for paragraph in document.paragraphs:
if date not in paragraph.text:
document.add_heading(date)
document.save('example.docx')
duplicate(document)
添加'duplicate(document)'作为代码的最后一行。你已经定义了一个函数,但从来没有调用它 – inspectorG4dget
感谢您的回答。现在它创建一个标题,但也重复。 – BohdanS