[New-bugs-announce] [issue45297] Improve the IDLE shell save command

Steven D'Aprano report at bugs.python.org
Sun Sep 26 20:28:07 EDT 2021

New submission from Steven D'Aprano <steve+python at pearwood.info>:

See this question on Discuss:


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.

assignee: terry.reedy
components: IDLE
messages: 402686
nosy: steven.daprano, terry.reedy
priority: normal
severity: normal
status: open
title: Improve the IDLE shell save command
type: enhancement
versions: Python 3.11

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list