How can I create an indefinite iterations of objects in python?
I'm new to python and am trying to create a program to test some methods
of object creation. Currently, I'm writing a program that involves
creating objects, giving them a unique numeric name, and assigning them to
a list for future referencing. Here's what I wrote to create the variable
names:
def getRectangleName():
rectName = list("Rectangle")
SPAWNEDOBJECTLIST.append(len(SPAWNEDOBJECTLIST))
rectName.append(str(len(SPAWNEDOBJECTLIST)))
return rectName
and then that's passed onto something to turn that string into a variable
name. I tried eval(), learned this was Bad for some reason and it didn't
work anyway, and tried some workarounds to no avail.
I figure there's plenty of games that have an indefinite number of
characters on the screen. Is there an established way of making iterations
of objects like this?
The objects themselves have an X and Y so that they act as reference
points for the display of rectangles on screen(the idea in the future is
to have each one move around on their own, so simply making lists of X and
Y to draw rectangles isn't useful).
Edit: The problem is that I don't know how to give each object its own
variable to put it on a list for future referencing.
No comments:
Post a Comment