May-02-2020, 03:34 PM
Hi All
I have the following code which reads the contents of a file, appends 1,2,3, etc to the contents and then writes the results to a new file:
Thanks for your help.
I have the following code which reads the contents of a file, appends 1,2,3, etc to the contents and then writes the results to a new file:
f = open("text-file.txt", "rt") s = f.read() f.close() f = open("new-text-file.txt", "wt") f.write(s + '1') f.write(s + '2') f.write(s + '3') f.close()The code is working but I want to append to the text string 200 times and wondered if there is a while loop or something like that I can use to achieve the same thing. I don't want to write out f.write(s + '4') 200 times.
Thanks for your help.