[Tutor] Dynamic creation of class instances...

Paul Sidorsky paulsid@shaw.ca
Wed, 22 May 2002 12:00:30 -0600


alan.gauld@bt.com wrote:

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

> 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.

Heh I've noticed that too.  Perhaps we need a Tutor FAQ?  I'd volunteer
to write one except I don't think I've been here long enough yet.

> 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 admit to having tried this as well when I first realized it could be
done.  I didn't really need it for anything, I just wanted to see if it
was feasible.  It didn't take too long for me to see that it wasn't, but
it was fun to try.  I think Python just makes it too easy to do, and
thus very tempting to try to use in practice.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/