Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-32984: IDLE - set __file__ for startup files #5981

Merged
merged 3 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ def execfile(self, filename, source=None):
if source is None:
with tokenize.open(filename) as fp:
source = fp.read()
if use_subprocess:
source = (f"__file__ = r'''{os.path.abspath(filename)}'''\n"
+ source + "\ndel __file__")
try:
code = compile(source, filename, "exec")
except (OverflowError, SyntaxError):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Set ``__file__`` while running a startup file. Like Python, IDLE optionally
runs one startup file in the Shell window before presenting the first interactive
input prompt. For IDLE, ``-s`` runs a file named in environmental variable
:envvar:`IDLESTARTUP` or :envvar:`PYTHONSTARTUP`; ``-r file`` runs
``file``. Python sets ``__file__`` to the startup file name before running the
file and unsets it before the first prompt. IDLE now does the same when run
normally, without the ``-n`` option.