Linux下读取doc,docx文件

docx文件
利用python-docx包,好像暂时不支持python3.6。

test.py

# -*- coding:utf-8 -*-
import sys
import docx

path = sys.argv[1]

file = docx.Document(path)
for para in file.paragraphs:
	print para.text

使用命令行传参数

python test.py filename

例子
在这里插入图片描述

doc文件

python-docx不支持doc文件的
我们可以使用antiword,下载完,解压,进入该文件,分别使用makemake install。安装完后,主目录会出现bin文件夹,用命令行进入。使用pwd查看该目录的路径。

使用su,输入密码,然后设置环境变量

PATH=$PATH:your's bin path(输入上面pwd出现的路径)

echo $PATH查看PATH是否成功导入。
成功导入后,我们就可以在任何的shell和路径使用antiword了。

EX
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_40965177/article/details/82991712