Ask coding questions

← Back to all posts
A python question
ia13ru (43)

I have a question which is in this post. I am reposting this as it has been ignored.
The post
Thank you in advance. :-)

Answered by ANDREWVOSS (187) [earned 5 cycles]
View Answer
Comments
hotnewtop
ANDREWVOSS (187)

The best solution would be to create a list:

objects = [object1,object2,object3]
for object in objects:
  object.function()
MadMath123 (343)

You can't reference a variable name in Python. The best solution would to make an array of objects, like @ANDREWVOSS wrote. The vars() function is used to get all class vars of an object into one dict (useful for debugging or referencing). If you want to make another object the same way as another, the vars() function might be useful.

ANDREWVOSS (187)

@MadMath123 I didn't even think of that, that's really clever.