This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improve the IDLE shell save command
Type: enhancement Stage:
Components: IDLE Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: steven.daprano, terry.reedy
Priority: normal Keywords:

Created on 2021-09-27 00:28 by steven.daprano, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg402686 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-09-27 00:28
See this question on Discuss:

https://discuss.python.org/t/what-is-this-syntax-i-dont-know-how-to-fix-it/10844

It seems that IDLE allows you to save the shell output, complete with welcome message and prompts, as a .py file, and then reopen it and attempt to run it, which obviously fails. When it does fail, it is confusing.

Suggested enhancements:

- When saving the complete shell session, save it to a text file, not .py. That would be useful for anyone wanting a full record of the interpreter session.

- When saving the shell session as a .py file, strip out the welcome message, the prompts, and any output, leaving only what will hopefully be runnable code.

I don't know what sort of UI this should have. Two different menu commands? A checkbox in the Save dialog?

My thoughts are that the heuristic to reconstruct runnable code from the interpreter session may not be foolproof, but better than nothing. Something like the doctest rules might work reasonably well.

- strip the welcome message;

- any line (or block) starting with the prompt >>> that is followed by a traceback should be thrown out;

- any other text not starting with the prompt >>> is interpreter output and should be thrown out;

- you should be left with just blocks starting with the prompt, so remove the prompt, adjust the indents, and hopefully you're left with valid runnable code.
msg415638 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2022-03-20 22:25
Here is another example of a newbie caught by this:

https://discuss.python.org/t/syntax-error-in-python-3-10-when-running-on-terminal/14462
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89460
2022-03-20 22:25:42steven.dapranosetmessages: + msg415638
2021-09-27 00:28:07steven.dapranocreate