I don't know why it tells me None. I have used Python docx library for doing this, I have tried multiple times but didn't find any satisfactory solution.
# Function to extract information about 'Abstract heading Font Style' from the document
def abstract_heading_font_style(word_file):
doc = Document(word_file)
font_styles = set()
for paragraph in doc.paragraphs:
if any(word in paragraph.text for word in ['Abstract', 'ABSTRACT', 'abstract']):
for run in paragraph.runs:
font_styles.add(run.font.name)
if any(word in paragraph.text for word in ['Abstract', 'ABSTRACT', 'abstract'])and run.bold:
font_styles.add(run.font.name)
return list(font_styles)
You're adding the font style to font_styles only if run.bold is True within the nested loop so if there are no bold runs in the paragraph containing 'Abstract' it will always return None since you're not returning anything outside the loop try using below code