bpo-32984: IDLE - set __file__ for startup files#5981
Conversation
| source = fp.read() | ||
| if use_subprocess: | ||
| source = (f"__file__ = r'{os.path.abspath(filename)}'\n" + | ||
| source + "\ndel __file__") |
There was a problem hiding this comment.
This gives a SyntaxError if there's an unescaped quote in the path or file name (such as /home/cheryl's/tests/).
Using triple quotes works:
f"__file__ = r'''{os.path.abspath(filename)}'''\n"
There was a problem hiding this comment.
Great catch. Changed.
| input prompt. For IDLE, -s runs a file named in environmental variable | ||
| IDLESTARTUP or 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thanks. by 'editing', I could see and copy the markup (and maybe learn better). I changed one clause to -r file runs file, which I can preview here ;-).
|
Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or 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. (cherry picked from commit 22c82be) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
|
GH-5986 is a backport of this pull request to the 3.7 branch. |
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or 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. (cherry picked from commit 22c82be) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
|
GH-5987 is a backport of this pull request to the 3.6 branch. |
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or 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. (cherry picked from commit 22c82be) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
|
Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6. |
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or 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. (cherry picked from commit 22c82be) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
|
GH-5993 is a backport of this pull request to the 3.6 branch. |
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or 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. (cherry picked from commit 22c82be) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Like Python, IDLE optionally runs one startup file in the Shell window before presenting the first interactive input prompt. For IDLE, option -s runs a file named in environmental variable IDLESTARTUP or 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.
https://bugs.python.org/issue32984