Issue
I hope you can help with something quite simple, but im clearly not having clarity working it out.
I have a bunch of images (image1.jpg, image2.jpg, image3.jpg...you get the picture.)
I have a python script that I would like to read a file which contains the number of the image last sent, increment it by 1, and save the file with the new number, so the next time it runs, it would pick up and increment the next number. Image1 becomes Image 2 etc etc
Ive done some looking around and failing miserably and overcomplicating what I think is something quite simple.
Can someone save me from my torment??
Thanks everyone!!
Solution
with open('file.txt','r+') as f:
data = int(f.read())
data += 1
f.truncate(0) # Go to the beginning of the file, clearing the file
f.write(str(data)) # write the data at the beginning of the file
Answered By - Simon Walker Answer Checked By - Mildred Charles (WPSolving Admin)