Create Word document with Python

How to create a simple word document using a python script.

First, download python-docx.

pip3 install python-docx

yes…I’m using Python3 now.

Then, this is how simple the rest is…

from docx import Document

str_title = 'This is the document Title'

# create the document
doc_output = Document()

# add the header
doc_output.add_heading(str_title, 0)

# add a paragraph
doc_output.add_paragraph('This is a paragraph')

# save the file'testing.docx')