Reading files is a breeze with the
python-docx module. Now, let's shift our focus to writing Word documents. We'll perform multiple operations with documents in this section.
For this recipe, we will use the same fantastic Python module,
python-docx. We don't need to spend much time on the setup. Let's get started!
.docxfile and then to add a heading to it. The following code performs this operation:
from docx import Document document = Document() document.add_heading('Test Document from Docx', 0) document.save('testDoc.docx')
This is how the document looks: