name-spaces and loading a file

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


Aahz Maruch wrote:
> 
> In article <8766vn2ijn.fsf at curious.eyeofdog.com>,
> Alex Shinn  <foof at eyeofdog.com> wrote:
> >
> >exec 'scene.' + var
> >
> >which only works for variables known by the main engine ahead of
> >time... it doesn't let the story author declare a new global in one
> >scene to be accessed by other scenes.
> 
> Any time someone starts talking about needing to access variables with
> non-predefined names, my first question is always: why not just create a
> dictionary and pass it around?  That way, each module contains a class
> that gets passed a reference to this dict at __init__; because it's a
> *reference*, all the instances see changes to the dict.
> 
> (I'll admit that I tend to deep-end on using dicts when they're not
> always the best solution, but I think that's better than the reverse
> problem.  To rephrase the Timbot's great advice: "Dicts are a honking
> great idea, let's use more of them!")

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?

Thanks.




More information about the Python-list mailing list