I want to have each instance of some class have a unique integer identifier based on the order that I create them, starting with (say) 0. In Java, I could do this with a static class variable. I know I can emulate the same sort of behavior with Python, but what would be the most ‘Pythonic’ way to do this?
Thanks
The following approach would be relatively pythonic (for my subjective judgement of pythonic – explicit, yet concise):
If you are facing a large number of classes, which need that kind of attribute, you could also consider writing a metaclass for that.
An example of a metaclass: http://www.youtube.com/watch?v=E_kZDvwofHY#t=0h56m10s.