[Tutor] creating variables at runtime

Kirby Urner urnerk@qwest.net
Wed, 23 Jan 2002 22:34:59 -0800


>
>I may be setting myself up for a big fall here because I have
>almost no experience with this kind of thing.  However, this
>program seems to work:
>
>class C:
>     pass
>
>names = []

Ah, but you're adding his new objects to a list now.  Not top
level.  names is top-level, but the new objects inside are not.
How do you add his named objects at the same level as your
names variable?

>I realize if you need to mix namespaces then things start to get a lot
>trickier, but for a one-module program the basic concept still seems the
>same as in the interpreter.  Please do correct me if I'm wrong, though!

You printed the list contents, which isn't that different
from adding objects to a dictionary (what I suggested
doing).  The challenge is to use a raw_input loop to
create user-named objects that are not contained inside
any list, tuple or map.

It's not that you're doing anything wrong.  I'm just trying
to make clear the distinction between creating new variables
at the top level, versus inside a program-provided data
structure.

Kirby