python - How to add an empty new line between concatenated files? -
i'm concadenating files this:
filenames = ['ch01.md', 'ch02.md', 'ch03.md', 'ch04.md', 'ch05.md'] open('chall.md', 'w') outfile: fname in filenames: open(fname) infile: outfile.write(infile.read()) the problem is, end this:
## title 1 text 1 ## title 2 text 2 and want this:
## title 1 text 1 ## title 2 text 2 how modify script that?
add them explicitly iterating on every line in infile , adding 2 line-breaks \n\n every time write line outfile:
with open(fname) infile: line in infile: outfile.write(line + "\n\n") edit: if need write after every file can write new lines after every file process, write() takes string argument , writes it:
open(fname) infile: outfile.write(infile.read()) outfile.write("\n\n")
Comments
Post a Comment