scope question in a switch mixin

browerg at browerg at
Thu Jan 17 00:02:17 CET 2008

Thanks for writing, and I'm sorry it's taken so long to get back to you. Python is fun for me -- dinner guests and my boss got in the way.

>> The code ... is the result of noodling around with switches as a learning tool. I've played with python for a few years, but I'm self-taught, so . . .
>> My question is, why are modules imported at the top of the program not visible to the functions Switch builds? There is
>> no problem when the import is in the function, but I thought initially that imports at the top would be in its globals.

>John wrote:
>The global namespace of the to-be-exec'ed code is the dictionary that 
>you supply. That dictionary doesn't contain "math".

Thank you for the guidance about namespaces and exec.

>It's a long time since exec has been documented as a *function*. Why? 
>Because it isn't:

. . . and the code snip.

>What book/tutorial did you get that from?

Hey, I'm not going to pass that off on anyone. As usual, self-education means missing a lot. 

I'm exploring your suggestions and working on my code. 

Thanks again.


More information about the Python-list mailing list