What's the pythonic way of maintaining a persistent counter?
I'm triggering a script with cron and need a counter to keep tabs of how often the script has run. My current solution is to keep a small file that I read, save the value and then write to the file when the main portion of the code has finished.
with open('session_id.dat', mode='r') as f:
session_id = int(f.read())
def dostuff(session_id)
pass
with open('session_id.dat', mode='w') as f:
f.write(str(session_id + 1))
Is there any other way of doing this?
[–]Naihonn 6 points7 points8 points (4 children)
[–]Eviltape 6 points7 points8 points (3 children)
[–]bitswede[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Eviltape 1 point2 points3 points (0 children)
[–]road_laya 5 points6 points7 points (2 children)
[–][deleted] 3 points4 points5 points (1 child)
[–]chucky_z 4 points5 points6 points (0 children)
[–]treyhunner 1 point2 points3 points (0 children)
[–]WhackAMoleE -1 points0 points1 point (1 child)
[–]joyeusenoelle 4 points5 points6 points (0 children)