Issue 18288: Idle 2.7: Run Module does not set file (original) (raw)

Created on 2013-06-23 19:10 by terry.reedy, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg191721 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-06-23 19:10
This is a 2.7 only bug. F:\Python\mypy\tem2.py ---- print (__file__) __file__ should be set to relative or absolute path. From command line: F:\Python\mypy> c:/programs/python27/python.exe tem2.py tem2.py F:\Python\mypy> c:/programs/python27/python.exe -m tem2 F:\Python\mypy\tem2.py 3.3 gives same results. From Idle editor window with Run Module (F5): 3.3: >>> F:\Python\mypy\tem2.py # same as python -m above, and same as when file is imported. 2.7: >>> Traceback (most recent call last): File "F:\Python\mypy\tem2.py", line 1, in print (__file__) NameError: name '__file__' is not defined This is the bug to be fixed, if reasonably possible. Both 2.7 and 3.3 set __file__ on regular import (or rather, Idle does not disable this). >>> import tem2 F:\Python\mypy\tem2.py I think the first step should be to try this on non-Windows systems.
msg191723 - (view) Author: Francis MB (francismb) * Date: 2013-06-23 19:40
On Debian: * Command line 2.7.3 ~/Prog/mypy$ python2.7 tem2.py tem2.py ~/Prog/mypy$ python2.7 -m tem2 /home/ci/Prog/mypy/tem2.py * IDLE 2.7.3 >>> print(__file__) Traceback (most recent call last): File "<pyshell#0>", line 1, in print(__file__) NameError: name '__file__' is not defined >>> >>> import tem2 tem2.pyc >>>
msg191725 - (view) Author: Francis MB (francismb) * Date: 2013-06-23 19:44
From Idle editor window (F5): >>> Traceback (most recent call last): File "/home/ci/Prog/mypy/tem2.py", line 1, in print(__file__) NameError: name '__file__' is not defined >>>
msg191745 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-06-24 05:52
Thanks, not specifically Windows then.
msg192086 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2013-06-30 21:24
See . The patch was not applied to 2.7.
msg192091 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-06-30 23:09
Thanks Roger, problem fixed.
History
Date User Action Args
2022-04-11 14:57:47 admin set github: 62488
2013-06-30 23:09:39 terry.reedy set status: open -> closedmessages: + dependencies: + idle "Run Module" (F5) does not set __file__ variableresolution: duplicatestage: test needed -> resolved
2013-06-30 21:24:03 roger.serwy set messages: +
2013-06-24 05:52:13 terry.reedy set messages: +
2013-06-23 19:44:37 francismb set messages: +
2013-06-23 19:40:47 francismb set nosy: + francismbmessages: +
2013-06-23 19:10:49 terry.reedy create