name-spaces and loading a file

David R. Favor dfavor at austin.ibm.com
Fri Feb 18 08:29:01 EST 2000


Moshe Zadka wrote:
> 
> On Fri, 18 Feb 2000, David R. Favor wrote:
> 
> > I am very new to python.
> >
> > Can you elaborate on this point. It sounds like it might work for an
> > application I'm working on.
> >
> > Specifically, in the case of:
> >
> >    exec 'from scenes.' + scene + ' import *'
> >
> > Do you mean that within each $scene class all methods pass a dictionary
> > as one of the arguments in method calls?
> 
> You do know $ is invalid in Python except inside strings, don't you?

Yes. Simply meant as a place holder.

> Anyway, my basic reponse to anyone using exec, especially using exec where
> he would step on all kind of global variables is "don't!". Why not do
> 
> module=__import__('scenes.'+scene)

I see.

> And access those variables you need from module? It's much more
> predictable. Actually, even __import__ troubles me: usually, my solution
> is to pickle dictionaries for this purpose.

So rather than having classes, keep a collection of persistent dictionaries
that represent each scene and simply load and unload as needed?

That would open other possibilities for optizations also, such as when a scene
is entered, all the ajoining scences could be background loaded in a thread so
that moving from one scene to another would be instantaneous (no lag for reading
the scenes from disk every time movement was made from one scene to another).

Nice.

Thanks.

> better-safe-then-sorry-ly y'rs, Z.

:-)




More information about the Python-list mailing list