Issue 8515: idle "Run Module" (F5) does not set file variable (original) (raw)

Created on 2010-04-24 01:18 by dangyogi, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
idle.patch dangyogi,2010-04-24 01:18 Patch file for idlelib/ScriptBinding.py in Python 2.6.5
Messages (8)
msg104066 - (view) Author: Bruce Frederiksen (dangyogi) Date: 2010-04-24 01:18
The python CLI always sets the __file__ variable, whether run as: $ python foobar.py or $ python -m foobar or $ python >>> import foobar # __file__ set in foobar module The idle program sets the __file__ variable properly when you do the import from the idle shell, but __file__ is not set with the "Run Module" (F5) command from the editor. I've included a patch file to set __file__, but it doesn't del it after the module has run. But maybe this is OK, because the os.chdir is not undone either???
msg107551 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2010-06-11 15:11
I believe IDLE runs modules via execfile(), so I would expect the behavior to be similar, and execfile() does not set __file__. Doing "Run Module" is also IMO equivalent to doing execfile(), so this behavior retains consistency. However, I would expect __file__ to be set when running IDLE -r