python - Python3 - Iterate over object methods with similar names -


i trying iterate list of object methods similar names. there clever way can this. have objects similar use iterator instead of making list of functions.

dog1.feed() dog2.feed() dog3.feed() dog4.feed() dog5.feed() ... 

all local object names in locals():

for in range(1,6):     locals()["dog" + str(i)].feed() 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

android - MPAndroidChart - How to add Annotations or images to the chart -