I have several opened files. Now, I need to write the same line in all of them. My current code is the following, but it is unelegant and very repetitive. Is there a way of doing it in less lines?
with open("a.txt", "a+") as fa,\
open("b.txt", "a+") as fb,\
open("c.txt", "a+") as fc,\
open("d.txt", "a+") as fd,\
open("e.txt", "a+") as fe,\
open("f.txt", "a+") as ff,\
open("g.txt", "a+") as fg:
fa.write("header")
fb.write("header")
fc.write("header")
fd.write("header")
fe.write("header")
ff.write("header")
fg.write("header")
In the rest of the program (not shown), I deal with each file differently, appending different information to each of them.
If this post is duplicate, I am sorry!