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