I'm not very clear on what you want. Do you want to automatically create objects, using a loop? If so, then the code your provided can't be used. You're creating a new object for the same variable,
name, all the time. To easily create multiple objects with a loop, you'll need to save the old objects in some way. This could be done using a list.
Code:
class Object:
def __init__(self, value):
self.value = value
def get(self):
return self.value
listOfObjects = []
for value in range(0, 10):
listOfObjects += [Object(value)]
for index in range(0, len(listOfObjects)):
print listOfObjects[index].get()
I've defined a function,
get, so you can see that there really is multiple objects, with different
values. If you want a nicer representation, than using
get, you can overload either __repr__ or __str__.
Code:
# ...
def __str__(self):
return str(self.value)
# ...
for index in range(0, len(listOfObjects)):
print listOfObjects[index]