name-spaces and loading a file
Aahz Maruch
aahz at netcom.com
Fri Feb 18 00:59:18 EST 2000
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!")
--
--- Aahz (Copyright 2000 by aahz at netcom.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
Our society has become so fractured that the pendulum is swinging
several different directions at the same time
More information about the Python-list
mailing list