[Solved] creating an instance in a for loop


dir() produces a sorted list of names; these are just strings. They are not references to the actual objects. You can’t apply a call to a string.

Use the globals() dictionary instead, this gives you a mapping with both the names and the actual objects:

for name, obj in globals().items():
    if not name.startswith('__'):
        print "name =", name
        instance = obj()
        instance.replay()

dir() at the module level, without arguments, essentially returns sorted(globals()).

3

solved creating an instance in a for loop