Python Only Writes One of Three docs Using open() read() write() -


i have multiple html files copy+pasted single word doc reporting.

i'm trying combine files opening file1 , copying test.doc. then, open file2 , append test.doc, , on.

python writes file1 test.doc, , seems skip file2 , file3.

i've tried looping through each file , writing, had same result. i've tried few different file types, changing .html .txt .

i think <html>report contents</html> stopping it.

a push in right direction appreciated!

import os       file in os.listdir(os.getcwd()):         newname = os.path.splitext(file)         if '.html' in file:             newfile = file.replace('.html', '.doc')             os.rename(file, newfile)     else:         print('no html files convert, writing report')      mainfile = open('test.doc', 'a')     file1 = open('filetocopy1.doc', 'r')     read1 = file1.read()     mainfile.write(read1)     file1.close()      file2 = open('filetocopy2.doc', 'r')     read2 = file2.read()     mainfile.write(read2)     file2.close()      file3 = open('filetocopy3.doc', 'r')     read3 = file3.read()     mainfile.write(read3)     file3.close()      mainfile.close()      exit() 


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -