for example:
obj1 = ClassName()
obj1.name = "name1"
obj2 = ClassName()
obj2.name = "name2"
obj3 = ClassName()
obj3.name = "name3"
obj4 = ClassName()
obj4.name = "name4"
and we have static variable that return number of objects:
ClassName.counter
How i can get obj1.name, obj2.name and other, but if objects count can be dynamic(using cycle for example) ?
PS: more good if you can say me how to do that in the python, but only design will be good also.
Well… it’s actually not recommended to do this type of staff, being a little incomprehensible and prone to bugs…however, you could do it this way:
It works. It’s ugly. Using some external factory to handle it is probably much better. If you want to store links to existing instances, some array/dictionary with weakrefs would probably be a fine solution.