接受跟踪更改并使用CATDOC将.doc转换为.txt

2024-04-24 12:50:44 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在使用catdoc将.doc文件转换为.txt文件时接受轨迹更改?你知道吗

假设有两个文件'原件.doc'和'已修改.doc'. 你知道吗

'原件.doc'有以下句子:this a test sentence '已修改.doc'有以下句子:this is a test statement

当我转换已修改.doc到一个.txt文件而不是得到this is a test statement我得到的是this is a test sentence statement

我正在使用下面的代码。你知道吗

def doc_to_text_catdoc(filename):
(fi, fo, fe) = os.popen3('catdoc -w "%s"' % filename)
fi.close()
retval = fo.read()
erroroutput = fe.read()
fo.close()
fe.close()
if not erroroutput:
    return retval
else:
    raise OSError("Executing the command caused an error: %s" % erroroutput)

Tags: 文件testtxtclosedocisthissentence