I have codes just like follows:
class test:
def do_something():
pass
test1 = test()
test2 = test()
test3 = test()
test4 = test()
test5 = test()
test6 = test()
test7 = test()
test8 = test()
test9 = test()
...
Now I need invoke each instance’s function, just like that:
test1.do_something()
test2.do_something()
test3.do_something()
test4.do_something()
test5.do_something()
test6.do_something()
test7.do_something()
test8.do_something()
test9.do_something()
...
Too many classes, so I thought may be a for loop can complete the work:
for i in range(1, 30):
("test" + str(i)).do_something()
Of course it doesn’t work, for string doesn’t have do_something() function, can anyone have any idea to realize the function?
Use a
listordictto store your variables. For example: