So, I have a list containing several instances of the class.
As I move forward, I would like to call the method runfor the class at every step .
So far I have what is below. But is there a better or more Pythonic way to achieve the block for c in objs:?
Thank!
class the_class:
def __init__(self):
self.num=1
def run(self):
self.num+=1
def main():
objs=[]
objs.append(the_class())
objs.append(the_class())
objs.append(the_class())
for t in range(10):
for c in objs:
c.run()
print objs[0].num
main()
source
share