Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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阅读文档_Python - Fatal编程技术网

用python阅读文档

用python阅读文档,python,Python,我试图用python读取文档,但并没有得到任何错误,但它也并没有显示文档中所写的内容 from docx import Document import os file = open('C:\\Users\\hamza\\Desktop\\Python\\qwe.docx','r', encoding='utf8' ) document =(file.read()) file.close() 尝试pip安装docx2txt from docx2txt import process imp

我试图用python读取文档,但并没有得到任何错误,但它也并没有显示文档中所写的内容

from docx import Document

import os


file = open('C:\\Users\\hamza\\Desktop\\Python\\qwe.docx','r', encoding='utf8' )

document =(file.read())
file.close()

尝试
pip安装docx2txt

from docx2txt import process
import os
path = r'C:\Users\hamza\Desktop\Python\qwe.docx'
text = process(path)

with open(os.path.basename(path) + '.txt', 'w') as f:
    f.write(text)

参考此-这是否回答了您的问题?