R. David Murray added the comment:

The fact that the print works should be a clue that Python is in fact finding 
the module and importing it.  So your problem actually has to do with 
namespaces, which is something you have to think about when using exec or 
execfile.  You can see this by replacing your import with any variable setting 
(say, a=1) and referencing that in the class body.

The problem here is that execfile is operating inside a function, therefore the 
local and global namespaces are different.  wintypes gets imported into the 
*local* namespace.

Now, if you inline this type of code by hand, wintypes (or a) is found in the 
local namespace when the class statement is executed.  But when it is done via 
execfile, it is not.  

I'm not clear on whether or not this is a bug, but if it isn't there is 
certainly missing documentation in the description of execfile.

----------
nosy: +benjamin.peterson, r.david.murray
title: execfile/exec messes up with imports in executed file -> execfile/exec 
execution of class statement does not access locals()
type:  -> behavior
versions:  -Python 3.1

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16781>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to