DECROMAX

Counter that stores and retrives to file

Jun 26th, 2023
1,437
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | Source Code | 0 0
  1. # stores index of list or iterable to file, retrives count
  2.  
  3. def store_counter(counter):
  4.     # Store the counter value to a file
  5.     with open('counter.txt', 'w') as file:
  6.         file.write(json.dumps(counter))
  7.  
  8.  
  9. def retrieve_counter():
  10.     # Retrieve the counter value from the file
  11.     with open('counter.txt', 'r') as file:
  12.         counter = json.load(file)
  13.     return counter
  14.  
  15.  
  16. def main():
  17.     try:
  18.         counter = retrieve_counter()
  19.     except FileNotFoundError:
  20.         counter = 0
  21.  
  22.     for i in player_links[counter:]:
  23.         # do somthing
  24.  
  25.         counter += 1
  26.         store_counter(counter)
Advertisement
Comments
Add Comment
Please, Sign In to add comment