From ee1134d87d45cc487be10684b7c9a1ba0e4c8e93 Mon Sep 17 00:00:00 2001 From: yoniy Date: Sun, 17 Jul 2022 18:59:32 +0300 Subject: [PATCH] Improving Paragraph.text performance by 500%~ --- docx/text/paragraph.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docx/text/paragraph.py b/docx/text/paragraph.py index 4fb583b94..ec211732f 100644 --- a/docx/text/paragraph.py +++ b/docx/text/paragraph.py @@ -126,10 +126,9 @@ def text(self): Paragraph-level formatting, such as style, is preserved. All run-level formatting, such as bold or italic, is removed. """ - text = '' - for run in self.runs: - text += run.text - return text + if not self.runs: + return '' + return ''.join([run.text for run in self.runs]) @text.setter def text(self, text):