Message 178177 - Python tracker

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Content
When a Python file is exec()uted, it magically fails to find names in imported modules. The most magical thing in the examples below (b3.py in attach for Python 3) is that first reference to wintypes.LONG in print statement is actually successfull.

--- a.py
from ctypes import wintypes

print(wintypes.LONG)

class LOGFONT(object):
  field = wintypes.LONG


--- b2.py (Python 2 version)
def main():
  execfile('a.py')
main()


--- Output
<class 'ctypes.c_long'>
Traceback (most recent call last):
  File "b2.py", line 4, in <module>
    main()
  File "b2.py", line 2, in main
    execfile('a.py')
  File "a.py", line 5, in <module>
    class LOGFONT(object):
  File "a.py", line 6, in LOGFONT
    field = wintypes.LONG
NameError: name 'wintypes' is not defined