从 docx 中读取文本作为段落并将段落作为字符串保存到列表中
Reading in text from docx as paragraphs and saving paragraphs as string to a list
我阅读了 docx 文档中的段落,有效。现在,我想将每个段落作为字符串存储到列表中。我写了下面的代码 运行 它。
from docx import Document
sentences = []
document = Document('/path/to/*.docx')
for para in document.paragraphs:
print(para.text)
para = para.text
sentences = sentences.append(para)
并得到这个错误:
AttributeError: 'NoneType' object has no attribute 'append'
有谁知道如何得到我想要的输出?
使用
sentences.append(para)
而不是:
sentences = sentences.append(para)
List.append() 函数 returns None
我阅读了 docx 文档中的段落,有效。现在,我想将每个段落作为字符串存储到列表中。我写了下面的代码 运行 它。
from docx import Document
sentences = []
document = Document('/path/to/*.docx')
for para in document.paragraphs:
print(para.text)
para = para.text
sentences = sentences.append(para)
并得到这个错误:
AttributeError: 'NoneType' object has no attribute 'append'
有谁知道如何得到我想要的输出?
使用
sentences.append(para)
而不是:
sentences = sentences.append(para)
List.append() 函数 returns None