Detect paragraph break and put it in new variable in Python 3

Question:

I have a docx file, I opened it in PyCharm using textract. The docx contains a text with multiple paragraphs. What I want to do is detect every paragraph break and put every paragraph in a separate variables or as a list as string to use for later?

How can I do that in Python 3?

Please help!

I haven’t anything on the same.

Asked By: Swapnil MIB

||

Answers:

You can achieve that by using Document from docx

from docx import Document
document = Document('path/to/your/file.docx')
paragraphs = [para.text for para in document.paragraphs]
Answered By: David Meu
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.