[英]'NoneType' object has no attribute 'insert'. This error occurs when I try to insert popped value in array
[英]AttributeError: 'NoneType' object has no attribute 'name' error occurs when I try to get a heading of a docx file
我是 python 編程的新手。 我正在使用docx
模塊來處理文檔。 當我嘗試使用讀取DOCX從文件標題paragraph.style.name
,我得到:
AttributeError: 'NoneType' object has no attribute 'name'
我的腳本:
from docx import Document
document=Document('C:\\Users\\abc\\Desktop\\check\\Leave_Policy_converted.docx')
for paragraph in document.paragraphs:
if paragraph.style.name == 'Heading 1':
print (paragraph.text)
請澄清我。 先感謝您。
這意味着您正在訪問屬性的內容是None
(不是真正的值)。
你需要檢查paragraph.style
如果是None
,而不是訪問.style.name
。
if paragraph.style is not None and paragraph.style.name == 'Heading 1':
print(paragraph.text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.