Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用mammoth将.docx文件转换为与.docx同名的html文件_Python_Python 2.7_File_File Handling_Mammoth - Fatal编程技术网

Python 使用mammoth将.docx文件转换为与.docx同名的html文件

Python 使用mammoth将.docx文件转换为与.docx同名的html文件,python,python-2.7,file,file-handling,mammoth,Python,Python 2.7,File,File Handling,Mammoth,我有一个将(.doc)转换为HTML文件的代码。代码是: 导入猛犸象 f=打开(“c:..\\demo.docx”,“rb”) b=打开(“ABC.html”、“wb”) document=mammoth.convert_to_html(f) b、 写入(document.value.encode('utf8')) 现在将创建ABC.html。相反,我需要使用与docx文件相同的名称转换HTML文档。您可以决定输出文件使用哪个文件名-您可以使用相同的名称: dir = 'c:\...' fil

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

导入猛犸象
f=打开(“c:..\\demo.docx”,“rb”)
b=打开(“ABC.html”、“wb”)
document=mammoth.convert_to_html(f)
b、 写入(document.value.encode('utf8'))

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

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

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")