Created
April 11, 2025 01:00
-
-
Save starkayc/bfdde43b06731316da10f4f63b4a6d76 to your computer and use it in GitHub Desktop.
Increases the number after each run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| file_path = "counter.txt" # You can also use an absolute path if needed | |
| # Make sure the file exists and read the current count | |
| if not os.path.exists(file_path): | |
| count = 0 | |
| else: | |
| with open(file_path, "r") as f: | |
| content = f.read().strip() | |
| if content.isdigit(): | |
| count = int(content) | |
| else: | |
| count = 0 | |
| # Increment the count | |
| count += 1 | |
| # Write the new count back to the file | |
| with open(file_path, "w") as f: | |
| f.write(str(count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment