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

IDLE Default Working Directory

> On Nov 15, 2018, at 2:44 PM, eryk sun <eryksun at gmail.com> wrote:
> 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).
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Actually, I do not provide code to change the working directory.  

As with the original poster, I teach students who *never* use the command line.  All work is done using IDLE, which simplifies their environment.   IDLE (and PyCharm) apparently set the working directory appropriately and relative paths always work properly.