[Python-ideas] 'from os.path import FILE, DIR' or internal structure of filenames

Cameron Simpson cs at zip.com.au
Mon Sep 30 00:17:46 CEST 2013


On 29Sep2013 20:39, anatoly techtonik <techtonik at gmail.com> wrote:
| On Sun, Sep 29, 2013 at 2:26 AM, Cameron Simpson <cs at zip.com.au> wrote:
| > Maybe I'm grumpy this morning (though I felt the same reading this yesterday).
[...]
| > -1 because this is trivial trival code.
| > -1 because you can do all this with relative paths anyway, no need for abspath
[...]
| With all -1 above, what is your preferred way to refer to resources
| that are places into subdirectories of your script directory?

Probably os.path.join(os.path.dirname(__file__), "datafile-here").
I've got some unit tests that want that.

No need for abspath at all.

Of course, chdir and passing paths to programs-which-are-not-my-children
present scope for wanting abspath, but in the very common simple
case: unnecessary and therefore undesirable.

And I'm aware that modules-inside-zip-files don't work with this;
let us ignore that; they won't work  with abspath either:-)

It is so trite that I can't imagine wanting to bolt it into the stdlib.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

Thousands of years ago the Egyptians worshipped cats as gods.
Cats have never forgotten this. - David Wren-Hardin <bdh4 at quads.uchicago.edu>


More information about the Python-ideas mailing list