[Tutor] Dynamic creation of class instances...

dman dman@dman.ddts.net
Fri, 24 May 2002 14:11:42 -0500


--yrj/dFKFPuw6o+aM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, May 22, 2002 at 02:02:00PM +0100, alan.gauld@bt.com wrote:
| >  Right now I start out with a list of names, craft a string that=20
| >  looks like a class instantiation and then exec the sucker. =20
|=20
| Paul has already answered this based on a dictionary solution.
|=20
| But this is an issue for everyone on the list.
|=20
| 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.

I was noticing the same thing.

| It suggests to me that something in the standard tutorials/texts=20
| must be suggesting this solution to people. Its such a bizarre
| solution that it never seems to come up in any of the other=20
| fora that I engage with(Delphi, C++, Smalltalk, Java(spit!) ).
|=20
| But on Python it seems like most newbies sooner or later come=20
| up with this amazing idea for naming objects using exec.
|=20
| So Why? Comments welcomed from newbies who've been there, or=20
| from newbies whpo nearly went there or from exorerienced hackers=20
| who might know why it comes up so often?

My hypothesis is that the people asking these questions haven't used
C, C++, Java, Delphi or Smalltalk.  I don't know Delphi or Smalltalk,
but in C/C++/Java (and Eiffel and Lisp) you can't create variables at
runtime.  In those environments, data structures and containers are
introduced fairly early on.

I think that as newbies work through python they come across 'exec'
before they understand containers and how to use them.  They fail to
observe that the local namespace is just another container, though it
is special in the way objects are inserted into and extracted from it.
=20
| I am seriously puzzled and if I can do anything in my tutor to
| circumvent it(short of discussing it explicitly!) I will.

Go ahead and discuss it explicitly.  Also be sure and give a thorough
introduction to containers and when/where/why/how to use them.  (I'm
saying this in general, I don't know how well or how poorly your book
does this already)

-D

--=20

He who finds a wife finds what is good
and receives favor from the Lord.
        Proverbs 18:22
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--yrj/dFKFPuw6o+aM
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjzukG4ACgkQO8l8XBKTpRRDsgCeKDeEc7vnxsKiyuryhzYLrVK7
D+MAoI0z6o59CfSY1oP44CXf+e+bu3Gi
=5s7c
-----END PGP SIGNATURE-----

--yrj/dFKFPuw6o+aM--