See the video to understand:-
This is a small demo on how you can read old data from a file and write new data in the same file in for loop statement.
Hope you like the tutorial.
Python is simple and fun to play with and yet very powerful. 🔥
This is a small demo on how you can read old data from a file and write new data in the same file in for loop statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #Saving the last session in a text file #And continue from where we left import time try: #Reading text file read_url = "text.txt" f = open(read_url, "r") lines = f.readlines() #print(lines[0]) for i in range(int(lines[0]) , 60): print(str(i)+" -- "+" Seconds") f.close() g = open("text.txt","w") g.write(str(i)) g.close() time.sleep(1) except: #No text file? Then Create one f = open("text.txt","w") f.write(str('1')) #Giving it an input 1 print("This file was not present so I have created one.") f.close() time.sleep(1) print("Re-Run the Script Now it will work the way you want.") |
Hope you like the tutorial.
Python is simple and fun to play with and yet very powerful. 🔥