Skip to content
Advertisement

I need to write the output to a file and the file needs to look exactly like the output [closed]

import time

while True:
  for x in range(1, 1000, 1) :
    link = ("example.com/" + str(x))  
    print(link)
    time.sleep(0.1)

Here is the code, I need the link variable to be written to a file like

example.com/1
example.com/2
example.com/3

and so on

The problem i ran into before posting this is that when I write something to a file (example.com/1) in the next cycle the text gets replaced by the new output (example.com/2). Is there a way for me to write to the file in such a way that the script wouldnt replace the already existing lines and start from a new one every cycle

P.S this is my first post and im new to python, pls dont attack me if I did anything wrong!

Advertisement

Answer

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement