Typeerror: sequence item 0: expected str instance, Paragraph found
Typeerror: sequence item 0: expected str instance, Paragraph found
我正在使用下面的代码打开一个 doc 文件并将段落作为字符串存储在 Django 视图中。
doc = docx.Document('media/%s'%(filename))
fulltext = []
for para in doc.paragraphs:
fulltext.append(para)
docdata1 ='\n'.join(fulltext)
我收到一个错误
Typeerror: sequence item 0: expected str instance, Paragraph found
str.join
方法需要一个字符串列表,而您却给它一个 Paragraph
对象列表。您应该检索 Paragraph
对象的 text
属性以附加到 fulltext
而不是:
fulltext.append(para.text)
我正在使用下面的代码打开一个 doc 文件并将段落作为字符串存储在 Django 视图中。
doc = docx.Document('media/%s'%(filename))
fulltext = []
for para in doc.paragraphs:
fulltext.append(para)
docdata1 ='\n'.join(fulltext)
我收到一个错误
Typeerror: sequence item 0: expected str instance, Paragraph found
str.join
方法需要一个字符串列表,而您却给它一个 Paragraph
对象列表。您应该检索 Paragraph
对象的 text
属性以附加到 fulltext
而不是:
fulltext.append(para.text)