[Tutor] Dynamic creation of class instances...

alan.gauld@bt.com alan.gauld@bt.com
Wed, 22 May 2002 14:02:00 +0100


>  Right now I start out with a list of names, craft a string that 
>  looks like a class instantiation and then exec the sucker.  

Paul has already answered this based on a dictionary solution.

But this is an issue for everyone on the list.

Why does this same question come up every month on this list?
It has to be one of the top FAQs for this mailing list.

It suggests to me that something in the standard tutorials/texts 
must be suggesting this solution to people. Its such a bizarre
solution that it never seems to come up in any of the other 
fora that I engage with(Delphi, C++, Smalltalk, Java(spit!) ).

But on Python it seems like most newbies sooner or later come 
up with this amazing idea for naming objects using exec.

So Why? Comments welcomed from newbies who've been there, or 
from newbies whpo nearly went there or from exorerienced hackers 
who might know why it comes up so often?

I am seriously puzzled and if I can do anything in my tutor to
circumvent it(short of discussing it explicitly!) I will.

Alan g.