-
Book Overview & Buying
-
Table Of Contents
Python Automation Cookbook - Third Edition
By :
Word documents (.docx) are another common document type for storing mainly text. They are typically generated with Microsoft Office, but other tools can also be used to produce compatible files. Word files are probably the most common means of sharing documents that need to be editable, but they are also common for distributing documents.
We'll see in this recipe how to extract text content from a Word document.
We'll use the python‑docx module to read and process Word documents:
$ echo "python-docx==1.2.0" >> requirements.txt
$ pip install -r requirements.txt
We have prepared a test file, available in the GitHub ch04/documents directory, called document‑1.docx, which we'll use in this recipe. Note that this document follows the same Lorem Ipsum pattern that was described in the test document for the Reading PDF files recipe.
python‑docx:
>>> import docx
document...