File exists but Python says 'not found'.
Dave Angel
davea at davea.name
Mon Jul 1 07:38:12 EDT 2013
On 07/01/2013 07:00 AM, prerit86 at gmail.com wrote:
> I got it. The working directory was different. Sorry, I'm new and didn't the working directory has to be the location of the data. I thought the location of .py file and data file should be same. Thanks! Es. Robert Kern.
>
Python didn't make that assumption, the author of the script did. By
using a relative name like train.csv, he is implicitly forcing Python to
use the current working directory.
If he had wanted the file to be found in the same directory as one of
the source files, he could have built an absolute path by using the
__file__ attribute of the module.
However, for non-const files, the source directory is generally a bad
place to put them.
Confounding things is the strange habit that Windows has of deciding
that the script location *should* be your current directory. I believe
Explorer does that if you right-click select a script.
--
DaveA
More information about the Python-list
mailing list