Just wondering if there's a way to use a while loop for file appending; I'm attempting to use a small data file that's just 4 numbers to write to itself the same file a specific number of times. In my test case I just want to do it twice.
My code:
with open('data.txt', "a+") as file:
i = 0
while i<3:
file.seek(0)
data = file.read()
file.write("\n")
file.write(data)
file.seek(0)
i += 1
my data:
1.2, 2.5,
3.7, 3.9
Basically, I want to be able to iterate from 0,1,2 stop at 3 for i, and while this is occurring I am appending the data to itself so my end result should look like this:
1.2, 2.5,
3.7, 3.9
1.2, 2.5,
3.7, 3.9
1.2, 2.5,
3.7, 3.9