如何在使用catdoc将.doc文件转换为.txt文件时接受曲目更改?
假设有两个文件" original.doc'和' modified.doc'。
' original.doc'有以下句子:this a test sentence
' modified.doc'有以下句子:this is a test statement
当我将modified.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)
答案 0 :(得分:0)
使用Antiword解决了这个问题。
(fi, fo, fe) = os.popen3('antiword -f "%s"' % filename)