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
Post a Comment