[Idle-dev] Suggestion to ScriptBinding.py

Joonas Paalasmaa joonas@olen.to
Wed, 14 Feb 2001 20:11:23 +0200


I've used Idle for a while and noticed its power in Python development,
but there is one thing that disturbs me when I'm using Idle.
The problem is that when I'm running a script with CTRL+F5 Idle uses
Python directory as default working directory, which causes problems
with scripts that open or write files with relative pathnames.

I am not an expert Python programmer, but I have used the following
change in my ScriptBinding.py's getfilename-function and it seems to
work fine.

####################################################################
    def getfilename(self):
        # Logic to make sure we have a saved filename
        # XXX Better logic would offer to save!
        if not self.editwin.get_saved():
            self.errorbox("Not saved",
                          "Please save first!")
            self.editwin.text.focus_set()
            return
        filename = self.editwin.io.filename
        if not filename:
            self.errorbox("No file name",
                          "This window has no file name")
            return
        separatedpathlist = string.split(filename,os.sep)[:-1]    #line
added
        os.chdir( string.join(separatedpathlist, os.sep)+os.sep ) #line
added
        return filename
####################################################################

Any comments?

Joonas Paalasmaa
|joonas@olen.to|