What is the Python equivalent of static variables inside a function?
A bit reversed, but this should work: If you want the counter initialization code at the top instead of the bottom, you can create a decorator: Then use the code like this: It’ll still require you to use the foo. prefix, unfortunately. (Credit: @ony)