【问题标题】:Converting .docx file to html file with same name as .docx using mammoth使用mammoth将.docx文件转换为与.docx同名的html文件
【发布时间】:2020-04-18 12:36:39
【问题描述】:

我有一个将 (.doc) 转换为 HTML 文件的代码。代码是:

import mammoth
f=open("c: ......\\demo.docx","rb")
b=open("ABC.html","wb") 
document=mammoth.convert_to_html(f) 
b.write(document.value.encode('utf8')) 

现在ABC.html 将被创建。相反,我需要将该 HTML 文档转换为与 docx 文件相同的名称。

【问题讨论】:

    标签: python python-2.7 file file-handling mammoth


    【解决方案1】:

    您决定为输出文件使用哪个文件名 - 您可以使用相同的名称:

    dir = 'c:\...'
    filename = 'demo'
    input_file = os.path.join(dir, filename + '.docx')
    output_file = filename + '.html'
    f = open(input_file, "rb")
    b = open(output_file,"wb") 
    

    【讨论】:

      猜你喜欢
      • 2023-03-05
      • 2022-06-10
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      • 2019-03-14
      • 2011-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多