Possible Duplicate:
Auto-incrementing IDs for Class Instances
I want to something like the following Java class in Python:
public class MyObject {
private static int ID = 0;
private final int id;
public MyObject() {
id = ID++;
}
}
In this Java code, every myObject
will have id
and there will be no way that two objects could have the same ID (it's a one-threaded application).
Can I do something like this in Python?