Python:AttributeError:“模块”对象没有属性“ WD_BREAK”

Dil*_*lip 3 python docx attributeerror

这是我的代码:

import docx

doc = docx.Document()
doc.add_paragraph('This is on first page!')
doc.paragraphs[0].runs[0].add_break(docx.text.WD_BREAK.PAGE)
doc.add_paragraph('This is on the second page!')
doc.save('twoPage.docx')
Run Code Online (Sandbox Code Playgroud)

错误是:

AttributeError: 'module' object has no attribute 'WD_BREAK'
Run Code Online (Sandbox Code Playgroud)

Sel*_*cuk 8

休息列入docx.enum.text。你应该改变

docx.text.WD_BREAK.PAGE
Run Code Online (Sandbox Code Playgroud)

docx.enum.text.WD_BREAK.PAGE
Run Code Online (Sandbox Code Playgroud)