[Python-checkins] cpython (2.7): Issue #8515: Set __file__ when run file in IDLE. Backport 2c276d0553ff by
terry.reedy
python-checkins at python.org
Mon Jul 1 01:08:18 CEST 2013
http://hg.python.org/cpython/rev/a958b7f16a7d
changeset: 84402:a958b7f16a7d
branch: 2.7
parent: 84399:231c122b44b6
user: Terry Jan Reedy <tjreedy at udel.edu>
date: Sun Jun 30 19:07:49 2013 -0400
summary:
Issue #8515: Set __file__ when run file in IDLE. Backport 2c276d0553ff by
Andrew Svetlov, based on initial patch by Bruce Frederiksen.
files:
Lib/idlelib/ScriptBinding.py | 12 ++++++------
Misc/ACKS | 1 +
Misc/NEWS | 3 +++
3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py
--- a/Lib/idlelib/ScriptBinding.py
+++ b/Lib/idlelib/ScriptBinding.py
@@ -152,16 +152,16 @@
dirname = os.path.dirname(filename)
# XXX Too often this discards arguments the user just set...
interp.runcommand("""if 1:
- _filename = %r
+ __file__ = {filename!r}
import sys as _sys
from os.path import basename as _basename
if (not _sys.argv or
- _basename(_sys.argv[0]) != _basename(_filename)):
- _sys.argv = [_filename]
+ _basename(_sys.argv[0]) != _basename(__file__)):
+ _sys.argv = [__file__]
import os as _os
- _os.chdir(%r)
- del _filename, _sys, _basename, _os
- \n""" % (filename, dirname))
+ _os.chdir({dirname!r})
+ del _sys, _basename, _os
+ \n""".format(filename=filename, dirname=dirname))
interp.prepend_syspath(filename)
# XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still
# go to __stderr__. With subprocess, they go to the shell.
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -317,6 +317,7 @@
John Fouhy
Stefan Franke
Martin Franklin
+Bruce Frederiksen
Robin Friedrich
Bradley Froehle
Ivan Frohne
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -73,6 +73,9 @@
IDLE
----
+- Issue #8515: Set __file__ when run file in IDLE.
+ Initial patch by Bruce Frederiksen.
+
- Issue #5492: Avoid traceback when exiting IDLE caused by a race condition.
- Issue #17511: Keep IDLE find dialog open after clicking "Find Next".
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list