You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee='https://github.com/terryjreedy'closed_at=<Date2018-03-05.19:46:08.581>created_at=<Date2018-03-02.17:13:39.384>labels= ['3.8', 'expert-IDLE', 'type-bug', '3.7']
title='IDLE: set and unset __file__ for startup files'updated_at=<Date2018-03-05.19:46:08.580>user='https://github.com/terryjreedy'
'python somefile.py' sets main.__file__ to 'somefile.py'. 'python' leaves __file__ unset. If PYTHONSTARTUP is set to somefile.py, 'python' executes somefile.py in main with __file__ set to 'somefile.py', then unsets __file__ before the >>> prompt, as if somefile has not been executed. Any explicit setting of __file__ in somefile is undone.
> F:\dev\3x> set PYTHONSTARTUP=f:/python/a/tem2.py
> F:\dev\3x> python
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__file__' is not defined
When the IDLE GUI process is started, its main.__file__ is set to the idlelib .py file used to start the process. If IDLE is started with -n, so that user code is run in the same process (the original mode), the -r or -s startup file and code entered at >>> sees this value*, rather than the user startup file name or a NameError.
I am not sure why it does not see the value of __file__ in the pyshell module, which I would expect to be '.../idlelib/pyshell.py'.
The change proposed above would fix __file__ for -n also, but would disable any subsequently executed idle code that uses __file__ that gets unset. So I think the wrapping should be conditioned on use_subprocess (True unless -n).
With the PR, IDLE behaves the same as Python on Windows.
.../3x> python -m idlelib -r f:/python/a/tem2.py
(see original post for content of tem2.py)
prints __file__ instead of raising NameError, while
>>> __file__ continues to raise NameError
Cheryl, I really expect the PR to work on linux, but can you manually test it anyway? If you think the blurb needs rst markup and feel like adding some, go ahead.