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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -