Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将Docx转换为仅返回最后一行文本的文本_Python_Python 2.7 - Fatal编程技术网

Python 将Docx转换为仅返回最后一行文本的文本

Python 将Docx转换为仅返回最后一行文本的文本,python,python-2.7,Python,Python 2.7,我正在尝试将word docx转换为正常工作的文本。问题是,当我试图返回参数时,我只得到转换文本的最后一行。但是,当我打印它时,它会打印所有已完成的文本 def word_text(test): for table in tables: for row in table.rows: for cell in row.cells: for paragraph in cell.paragraphs:

我正在尝试将word docx转换为正常工作的文本。问题是,当我试图返回参数时,我只得到转换文本的最后一行。但是,当我打印它时,它会打印所有已完成的文本

def word_text(test):
    for table in tables:
        for row in table.rows:
            for cell in row.cells:
                for paragraph in cell.paragraphs:
                    print (paragraph.text.encode("utf-8"))
                    return (paragraph.text.encode("utf-8"))

因为您只能返回一次。一旦
return
ed,它将不会返回

因此,我建议您使用
列表
并将
文本
添加到
列表
中,然后在最后添加
返回列表