osdir.com


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

IDLE Default Working Directory


On 11/14/18, Irv Kalb <Irv at furrypants.com> wrote:
>
> When working with data files, I tell students to put their project (their
> main program and any other related files) in a folder.  Then, in their calls
> to "open", I tell them to just give the name of the data file e.g.,
> 'MyData.txt', or a path relative from the current folder, e.g.,
> 'MyData/DataFile.txt'.  That makes things simple in a teaching environment
> and works on both Macs and Windows.

I hope you provide code to change the working directory to the script
directory (e.g. based on __file__, assuming it's not a frozen script).
Don't let them assume that these are the same. A process can be
started with any valid working directory. If you double click on a
script in Explorer, it happens to set the working directory to the
script directory. That's not necessarily the case for the Win+R run
dialog, a shell command line, or generally any call that runs the
script (e.g. system, spawnl, or WinAPI ShellExecuteEx and
CreateProcess).