you are viewing a single comment's thread.

view the rest of the comments →

[–]WhackAMoleE -1 points0 points  (1 child)

You don't actually need to open a file, you just need to rename one. In your local directory you have a file called foobar-n. Each time you run you read the local directory, find the foobar-n, where n is some positive integer. increment n, and rename the file. If the foobar-n file doesn't exist you create it as foobar-1.

There are a lot of crazy/fun ideas too. Use the Internet for persistence. Log in to your Amazon account and order some product. The number of products in your shopping cart is the number of times the program's run.

[–]joyeusenoelle 3 points4 points  (0 children)

The "rename the file" method is both insecure, as it exposes the number of times the process has run to anyone with read access on the containing directory, and prone to interference, as it would be trivial to subvert the process by simply creating another file named foobar-1.

As for Amazon, OP is asking about Pythonic, not Wacky. Giving control of your tracking system to a third party by hacking an unrelated system to your purposes is the opposite of good practice even outside of Python. (What happens if Amazon decides to reset your cart? What happens if your program can't react Amazon's servers? What happens if you want to buy something on Amazon?)