Nadpisywanie wartości w .txt

0

Program zapisuje czas uzyskany w zgadnięciu liczb a następnie zapisuje go w pliku test.txt problem polega na tym, że czas jest nadpisywany za poprzedni. Chcę by każdy kolejny czas był pod poprzednim.

# saving stats
test_file = open('d:\\test.txt', 'w')
test_file.write(('Time: %s'%t4))
if t4 > 15:
    test_file.write('\n')
    test_file.write('+15 sekund')
if t4 < 15 and t4 >= 5:
    test_file.write('\n')
    test_file.write('5~15 sekund')
if t4 < 5:
    test_file.write('\n')
    test_file.write('-5 sekund')
test_file.close()
1

Spróbuj:

test_file = open('d:\\test.txt', 'w+')
test_file.write("new line\n")
test_file.write(('Time: %s'%t4))
1
File = open('plik.txt', 'a+')

ewentualnie open('plik.txt', 'rw+') seek(0, 2) write(string)

1 użytkowników online, w tym zalogowanych: 0, gości: 1