from time import sleep with open('output.log', 'w', 1) as output: for i in range(1, 15): output.write('Line #{number}\n'.format(number = i)) sleep(1)