import docx
file_name = 'H:\树莓派工作\大创项目.docx'
def get_docx(file_name):
d = docx.opendocx(file_name)
doc = docx.getdocumenttext(d)
return doc
doc = get_docx(file_name)
print(doc) # 输出行数:1075
for d in doc[:20]:
print(d) # 打印前5行
执行的时候会一下错误
Traceback (most recent call last):
File "G:/Test_Data/Pycharm/PyQt/Read_Data/test001.py", line 2, in <module>
import docx
File "E:\Python3.7\lib\site-packages\docx.py", line 30, in <module>
from exceptions import PendingDeprecationWarning
ModuleNotFoundError: No module named 'exceptions'
此时进入 E:\Python3.7\lib\site-packages\docx.py 将 from exceptions import PendingDeprecationWarning 注释掉就可以了