IDLE Default Working Directory

Brian Oney brian.j.oney at googlemail.com
Wed Nov 14 03:43:13 EST 2018


On Tue, 2018-11-13 at 10:33 -0600, Bev in TX wrote:
> > On Nov 12, 2018, at 10:07 AM, Brian Oney <brian.j.oney at googlemail.com> wrote:
> > On Mon, 2018-11-12 at 09:35 -0600, Bev in TX wrote:
> > > I am not the OP and I’m on macOS — no shortcuts.  How would one do the same thing on other platforms?
> > > Bev in TX
> > Hello there,
> > I am not an IDLE user. You may try a startup script from python, as per the following. 
> > oney at oney:~$ cat pyhelp/change_to_current_dir.py #!/usr/bin/env python3
> > import osimport sys
> > os.chdir(os.path.dirname(os.path.abspath(__file__)))
> 
> Thanks so much for taking the time and effort to provide that script.  I experimented with it, but it does not work as desired in Idle.  I tried:* Changed to project directory and then opened Idle
>      Idle -> File-> Open still opens ~/Documents — not the project folder.
> * Placed the change folder script in ~/Documents, opened it in Idle and ran it 
>      Idle did not change to the project folder — it stayed in whichever folder the change folder script resided.
> 
> Unless someone can come up with a better option for macOS, the best that I can think of is to add the project folder to the side bar so that it is easier to access it in Idle -> File -> Open.
>      
Hi Bev

The idea is to put that script in the project folder.

You could begin your lecture with an introduction to the import system and command line. The script needs to reside in the desired directory. Once that is the case you would import it:

import path.to.script.sans.py.ending

It may be to much to ask of students. It's easiest to put that script in the project folder. You know have everthing in the same place, where students can copy that directory, take it whereever there is python installed, run that script, and pick up where they left off.

If you want to control where the directory changes to do this:

#!/usr/bin/env python3

import os
os.chdir('path/to/project/directory')


That is brittle though. What if the student don't all have access to that directory? What if they fail to put the project directory in the right place? What if the network drives are down and you end up working locally? 

You could send them a zip-file of everything including my first suggestion and it would just work.

HTH


More information about the Python-list mailing list