name-spaces and loading a file

Moshe Zadka moshez at math.huji.ac.il
Fri Feb 18 14:20:35 CET 2000


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?

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)

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.

better-safe-then-sorry-ly y'rs, Z.
--
Moshe Zadka <mzadka at geocities.com>. 
INTERNET: Learn what you know.
Share what you don't.





More information about the Python-list mailing list