Python Forum

Full Version: How to add run in paragraph using python-docx?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to put runs in one paragraph to another using , so I write code like this: But it does not work. How should I change this code?

from docx import Document
import re
                                                                                                                                                 
master = Document("out.docx")
po = master.add_paragraph('It is: ')
doc = Document("in4.docx")
for p in doc.paragraphs:
    if re.search('yyy', p.text):
        for r in p.runs:
            master.paragraphs[-1].runs.append(r)
master.save('out1.doc1')    
Thanks!