name-spaces and loading a file
Alex Shinn
foof at eyeofdog.com
Fri Feb 18 00:20:28 EST 2000
I'm new to Python and having trouble figuring out how to load a file.
Not importing a module, but just exec'ing a file within the current
context.
I'm working on an interactive story engine with the primary purpose of
making it easy for non-programmers to write story modules. A story
would be comprised of a collection of files, each describing a scene,
like the following:
title = "Passages"
background = "passages.png"
text = "You are in a maze of twisty passages, all alike."
option("Keep going", "passages")
option("Turn back", "cave_entrance")
so when you chose a scene, such as cave_entrance, it would load the
file with that name. Right now I'm using the following hack
exec 'from scenes.' + scene + ' import *'
but this doesn't give you access to the global story variables from
within the scene, and anything set in the scene has to be referenced
with
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.
Plus there are other quirks like having to use reload when going back
to an old scene.
Am I missing something simple, or is there no way to just load a file?
--
Alex Shinn <foof at eyeofdog.com>
More information about the Python-list
mailing list