On 7 May 2018 at 21:42, Nathaniel Smith firstname.lastname@example.org wrote:
On Mon, May 7, 2018, 03:45 Steven D'Aprano email@example.com wrote:
On Sun, May 06, 2018 at 09:33:03PM -0700, Nathaniel Smith wrote:
data_path = __filepath__.parent / "foo.txt"
more distracting than
data_path = joinpath(dirname(__file__), "foo.txt")
Why are you dividing by a string? That's weird.
[looks up the pathlib docs]
Oh, that's why. It's still weird.
So yes, its very distracting.
Well, yes, you do have to know the API to use it, and if you happen to have learned the os.path API but not the pathlib API then of course the os.path API will look more familiar. I'm not sure what this is supposed to prove.
I think it strongly suggests that *magically* introducing a path object into a module's namespace would be a bad idea, since it harms readability (since merely having `path` in the name isn't a strong enough hint that the object in question is a `pathlib.Path` instance).
Your original point is still valid though: given the boilerplate reduction already available via "from pathlib import Path; _this_dir = Path(__file__).parent", it's the pathlib version that needs to be taken as the baseline for how verbose the status quo really is, not the lower level os.path API (no matter how accustomed some of us may still be to using the latter).