Title: Allow running code without explicitly saving the file.
Type: enhancement Stage: resolved
Components: IDLE Versions: Python 3.7, Python 3.6
Status: closed Resolution: duplicate
Dependencies: Superseder: Idle: run from editor without explicit save
View: 19042
Assigned To: terry.reedy Nosy List: perilbrain, terry.reedy
Priority: normal Keywords:

Created on 2016-11-01 17:51 by perilbrain, last changed 2016-11-02 05:18 by terry.reedy. This issue is now closed.

Messages (4)
msg279885 - (view) Author: perilbrain (perilbrain) * Date: 2016-11-01 17:51
Current Flow:-
- If you create a new file in idle and try to run it, the editor asks to save the file. However if user presses cancel button the code is not executed.

I have been using idle for over 5 years and this behavior is quite annoying(along with paste :) !!). We are often required to copy code from various sites say some tutorial or code samples which are good for one time usage.

If a user presses cancel button then set a flag in IOBinding say "optedTemp", save it to a named temporary file, execute the code and close the file. If user again runs the code, check for this flag. If it is true then there is no need to ask for saving the code and again create the temporary file, execute, close. If some one needs to save this code they can use the "save as" menu which sets off the optedTemp flag.

Here is the code I propose (check for "#+++++++++++++++++++++")

# At top
import tempfile  #+++++++++++++++++++++

# New definition of functions:-

    def _run_module_event(self, event):
        filename = self.getfilename()
        tempCode = None #+++++++++++++++++++++
        if not filename:            
            tempCode = tempfile.NamedTemporaryFile(suffix = ".py") #+++++++++++++++++++++
            filename = #****Added***
   filename ) #+++++++++++++++++++++
   = True #+++++++++++++++++++++
            #return 'break'
        code = self.checksyntax(filename)
        if tempCode is not None: #+++++++++++++++++++++
            tempCode.close() #+++++++++++++++++++++
        return 'break'

    def getfilename(self):
        filename =
        if not self.editwin.get_saved():
            autosave = idleConf.GetOption('main', 'General',
                                          'autosave', type='bool')
            if autosave and filename:
            elif #+++++++++++++++++++++
                filename = None #+++++++++++++++++++++
                confirm = self.ask_save_dialog()
                if confirm:
                    filename =
                    filename = None
        return filename


def __init__(self, editwin):
        self.__id_print = self.text.bind("<<print-window>>", self.print_window)
        self.optedTemp = False #+++++++++++++++++++++

def save_as(self, event):
        filename = self.asksavefile()
        if filename:
            if self.writefile(filename):
                self.optedTemp = False #+++++++++++++++++++++
                except AttributeError:
msg279896 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-11-02 04:29
I agree that this is a problem that needs a solution. Your post gives the justification very well.  I already opened #19042 for this issue, so as is our usual policy, I am merging this duplicate into that one. 

Thank you for submitting a patch.  To apply it, we need a Contributor Agreement.  One can be signed electronically.  See  An '*' will appear after your name once a CA has been received and registered.  I will take a good look once this happens.

I the meanwhile, I will add a reference to this issue and patch, as well as additional comments, to #19042.
msg279897 - (view) Author: perilbrain (perilbrain) * Date: 2016-11-02 05:02
Thanks Terry, I tried searching for a similar issue but failed.

Feels like signing contributor form will take a while.
Meantime please feel free to tweak/improve and implement code in your way (Mine is a bit rough solution not even abiding by naming convention), if this is some licensing issue.
msg279899 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-11-02 05:18
In my additional comment, I explored the idea of running without saving, not even to a temp file.
Date User Action Args
2016-11-02 05:18:42terry.reedysetmessages: + msg279899
2016-11-02 05:02:43perilbrainsetmessages: + msg279897
2016-11-02 04:29:08terry.reedysetstatus: open -> closed
versions: + Python 3.6, Python 3.7, - Python 3.4
superseder: Idle: run from editor without explicit save
messages: + msg279896

resolution: duplicate
stage: resolved
2016-11-01 17:51:29perilbraincreate