osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

IDLE Default Working Directory


Thanks for taking the time to respond, but I?m not certain that we are on the same page.

 Every time you start Idle, its File -> Open dialog points to the same default location (on MacOS that is ~/Documents).  When you open a project?s file from another location, Idle remembers that new folder the next time that you use File -> Open.  However, it only does so during the current Idle session.  The next time you start Idle, you again have to traverse to your project?s folder.  The question is how to change Idle?s default File -> Open folder, so that one doesn?t have to traverse to the project?s folder every time one starts Idle. 

The OP is teaching a class on Windows.  A possible solution of modifying Idle?s startup folder in a shortcut was pointed out to the OP --  that was Windows specific.  Given my own little experiments, I?m not sure that Idle even pays attention to its startup folder, but that may work differently on Windows, so I can?t say for certain.

I only use macOS, so I wondered how to make Idle do the something similar on macOS (hence one reply to me mentioning using command-O, rather than ctrl-O, as would probably be used on Windows).

On macOS, I suggested adding the project folder to the side bar so that it is easier to access it in theIdle -> File -> Open dialog.  One could alternatively add an alias to the project folder in ~/Documents.  That would cut folder traversal down to one easily accessed level.  I suppose a similar thing could be done on Windows by adding a shortcut to the project folder in whatever the default File -> Open folder is on that platform. 

> On Nov 14, 2018, at 2:43 AM, Brian Oney <brian.j.oney at googlemail.com> wrote:
> ...
> 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
> 

AFAIK, one cannot specify a path on the import statement?  The following discussion indicates it?s not so straight forward...
https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path

I?m also not sure as to how this affects Idle?s File -> Open dialog?  

> 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')
> 

Again, doing this has no affect in Idle -> File -> Open

> 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.


Bev in TX