[Tutor] creating objects in a loop

Kirby Urner urnerk@qwest.net
Tue, 02 Apr 2002 13:00:33 -0800


>
>If you insist on creating top-level variables within
>the module, you can do it without exec as follows:
>
>for species,name in petlist:
>    globals()[species] = name

Sorry, that should have been:

for species,name in petlist:
    globals()[species] = Pet(name)

-- anyway, you get the idea.  I recommend the
dictionary method over the gobs-o-globals
approach.

Kirby