classification
Title: Idle 2.7: Run Module does not set __file__
Type: behavior Stage: resolved
Components: IDLE Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: 8515 Superseder:
Assigned To: Nosy List: Todd.Rovito, francismb, roger.serwy, terry.reedy
Priority: normal Keywords:

Created on 2013-06-23 19:10 by terry.reedy, last changed 2013-06-30 23:09 by terry.reedy. 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 <module>
    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 <module>
    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 <module>
    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 issue8515. 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
2013-06-30 23:09:39terry.reedysetstatus: open -> closed
messages: + msg192091

dependencies: + idle "Run Module" (F5) does not set __file__ variable
resolution: duplicate
stage: test needed -> resolved
2013-06-30 21:24:03roger.serwysetmessages: + msg192086
2013-06-24 05:52:13terry.reedysetmessages: + msg191745
2013-06-23 19:44:37francismbsetmessages: + msg191725
2013-06-23 19:40:47francismbsetnosy: + francismb
messages: + msg191723
2013-06-23 19:10:49terry.reedycreate