0

I read in a docx document and appended each paragraph to a list as a string using this code:

from docx import Document
paragraphs = []

document = Document('/path to/*.docx')
for para in document.paragraphs:
    para = para.text
    paragraphs.append(para)

Instead reading in each paragraph I would like to read in the whole text as one string and append it to a list. How do I have to modify the code above?

Tobitor
  • 1,388
  • 1
  • 23
  • 58

1 Answers1

2

You can simply concatenate all the paragraphs in a variable and then you can store the complete text in a list by appending as follows:

from docx import Document
text_com=""
paragraphs = []

document = Document('/path to/*.docx')
for para in document.paragraphs:
    text_com += para.text

paragraphs.append(text_com)