Making persistent changes to code per each time it runs?
Im not sure this is possible, but say I was making a program that tells you how many times its been run. The code would look something like:
times_run = 0
if __name__ == "__main__":
times_run += 1
print(times_run)
exit()
which is fairly simple. But the issues is that the change isn't persistent, so the next time it's run, it would put times_run at 1 instead of the desired 2. Does anyone have some resources on learning something like this?
11 comments · 87% upvoted · other discussions
As an inelegant but straightforward workaround, you can read/write that value to a text file elsewhere on your computer (probably the same directory where your script is or a subfolder).
japherwocky 7 points · Apr 2019
Yes! Time to learn about how to persist data to disk!
billsil 1 points · Apr 2019
If it’s with qt, they give you easy access to the registry. The registry is nice in that users tend to not mess with it. I store things like preferences (e.g., background color) and recent files there. I also store the window shape and location.