1

I have a code to convert (.doc) to HTML file. The code is:

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

Now ABC.html will be created. Instead, I need that HTML document to be converted with same name as docx file.

Mureinik
  • 297,002
  • 52
  • 306
  • 350

1 Answers1

1

You decide which file name to use for the output file - you could just use the same name:

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") 
Mureinik
  • 297,002
  • 52
  • 306
  • 350