New submission from anatoly techtonik:
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
----------
components: Interpreter Core
files: b3.py
messages: 178177
nosy: techtonik
priority: normal
severity: normal
status: open
title: execfile/exec messes up with imports in executed file
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file28434/b3.py
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue16781>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com