Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDLE: make interactive code savable as a runnable script #56047

Open
terryjreedy opened this issue Apr 12, 2011 · 9 comments
Open

IDLE: make interactive code savable as a runnable script #56047

terryjreedy opened this issue Apr 12, 2011 · 9 comments
Assignees
Labels
3.11 only security fixes topic-IDLE type-feature A feature request or enhancement

Comments

@terryjreedy
Copy link
Member

BPO 11838
Nosy @terryjreedy, @merwok

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

GitHub fields:

assignee = 'https://github.com/terryjreedy'
closed_at = None
created_at = <Date 2011-04-12.18:03:08.573>
labels = ['expert-IDLE', 'type-feature', '3.11']
title = 'IDLE: make interactive code savable as a runnable script'
updated_at = <Date 2021-09-27.06:31:28.437>
user = 'https://github.com/terryjreedy'

bugs.python.org fields:

activity = <Date 2021-09-27.06:31:28.437>
actor = 'terry.reedy'
assignee = 'terry.reedy'
closed = False
closed_date = None
closer = None
components = ['IDLE']
creation = <Date 2011-04-12.18:03:08.573>
creator = 'terry.reedy'
dependencies = []
files = []
hgrepos = []
issue_num = 11838
keywords = []
message_count = 9.0
messages = ['133592', '148781', '148783', '148786', '148947', '148949', '215870', '402691', '402694']
nosy_count = 2.0
nosy_names = ['terry.reedy', 'eric.araujo']
pr_nums = []
priority = 'high'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue11838'
versions = ['Python 3.11']

@terryjreedy
Copy link
Member Author

One can currently save the contents of a shell window exactly as is, with opening message, prompts, and restarts. This essentially a screenshot of the frame -- fine for an IDLE doc but not useful for rerunning the code.
Similarly, if one pastes in interactive input/output, with or without secondary prompts, into an edit window, it is a nuisance to edit.

This issue proposes an option to 'flip' code and output lines, with prompts deleted and outputs commented, so that

Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 1+2
3

becomes

#Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32
#Type "copyright", "credits" or "license()" for more information.
1+2
#3

(Ignore linewrap artifact on first line).

@merwok merwok changed the title IDLE: make interactive code runnable. IDLE: make interactive code savable as a runnable script Apr 15, 2011
@terryjreedy
Copy link
Member Author

Roger Serway pointed me to the PastePyShell.py extension that is part of the IdleX package http://idlex.sourceforge.net/
That does the conversion when *pasting* interpreter text into an edit window. I would have File/Save do the same thing when saving the shell text to a .py file.

@serwy
Copy link
Mannequin

serwy mannequin commented Dec 3, 2011

I considered saving directly from the shell but then I ran into a use-case problem. Saving the shell window as an runnable script will also save any syntax errors that were entered. A user would then have to open an editor to correct these errors.

A high-level task analysis would be as follows:
With "Save As Runnable", the user needs to save, open, and then fix.
With "Paste from Shell", the user needs to copy, paste, and then fix.

If you have suggestions for handling shell errors, I'm open to them.

@terryjreedy
Copy link
Member Author

Either way, it would be nice to have erroneous commands flagged or filtered. That can be detected when the first line of output is

Traceback (most recent call last):

I typically would copy, correct, and rerun a line until I get it correct, so I would want bad lines just removed. Others might prefer otherwise. I should take a look at your extension when I get a chance.

@serwy
Copy link
Mannequin

serwy mannequin commented Dec 7, 2011

This issue relates to bpo-1178

A traceback does not necessarily mean that the last statement had the error. For example:

>>> a = lambda: 1/0
>>> a()
    Traceback (most recent call last):
      File "<pyshell#1>", line 1, in <module>
        a()
      File "<pyshell#0>", line 1, in <lambda>
        a = lambda: 1/0
    ZeroDivisionError: integer division or modulo by zero

I suppose that the specification should be extended such that the above to get transformed to:

    a = lambda: 1/0
    #ERROR>>> a()
    #
    #Traceback  (most recent call last):
    #....

or something similar. Thoughts?

@terryjreedy
Copy link
Member Author

Interesting example. This issue is a bit more complicated than I thought. Clearly, the call that reveals an error in previous lines should not be simply deleted.

@terryjreedy terryjreedy added the type-feature A feature request or enhancement label Apr 9, 2014
@terryjreedy
Copy link
Member Author

bpo-21140 is about saving Output Window (renamed) as .txt instead of .py. Same method should be used to save shell log as .txt. My idea is that File menu for shell window should, if possible, have both

Save as log
Save as runnable code

@terryjreedy terryjreedy added the 3.7 (EOL) end of life label Jun 30, 2017
@terryjreedy terryjreedy self-assigned this Jun 30, 2017
@terryjreedy
Copy link
Member Author

This should be easier to do with the new shell with indents fixed.

@terryjreedy terryjreedy added 3.11 only security fixes and removed 3.7 (EOL) end of life labels Sep 27, 2021
@terryjreedy
Copy link
Member Author

In bpo-45297, Steven D'Aprano suggests deleting code immediately followed by traceback. (SyntaxErrors should not be there at all -- another issue.) But should NameError, for instance, be ignore, just because user printed something? Or block removed just because it comes before print statement?

Without more feedback, I believe most would want all code actually run. If there is a Traceback, Add comment with error and message.

UI is a tough issue. I don't want to add more File menu entries and hot keys. We can add to shell context menu as have already done.

Maybe this: after getting the save name, branch on type: .py, code only; anything else, full log. Subsequent ^S saves use last save-as name to decide.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes topic-IDLE type-feature A feature request or enhancement
Projects
Status: No status
Development

No branches or pull requests

1 participant