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.

Author steven.daprano
Recipients steven.daprano, terry.reedy
Date 2021-09-27.00:28:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632702487.28.0.152974990593.issue45297@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-09-27 00:28:07steven.dapranosetrecipients: + steven.daprano, terry.reedy
2021-09-27 00:28:07steven.dapranosetmessageid: <1632702487.28.0.152974990593.issue45297@roundup.psfhosted.org>
2021-09-27 00:28:07steven.dapranolinkissue45297 messages
2021-09-27 00:28:06steven.dapranocreate