<div dir="auto"><div><div class="gmail_quote"><div dir="ltr">On Mon, May 7, 2018, 03:45 Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, May 06, 2018 at 09:33:03PM -0700, Nathaniel Smith wrote:<br>
<br>
> How is<br>
> <br>
> data_path = __filepath__.parent / "foo.txt"<br>
> <br>
> more distracting than<br>
> <br>
> data_path = joinpath(dirname(__file__), "foo.txt")<br>
<br>
<br>
Why are you dividing by a string? That's weird.<br>
<br>
[looks up the pathlib docs]<br>
<br>
Oh, that's why. It's still weird.<br>
<br>
So yes, its very distracting.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
First I have to work out what __filepath__ is, then I have to remember <br>
the differences between all the various flavours of pathlib.<whatever>Path <br>
and suffer a moment or two of existential dread as I try to work out <br>
whether or not *this* specific flavour is the one I need. This might not <br>
matter for heavy users of pathlib, but for casual users, it's a big, <br>
intimidating API with:<br>
<br>
- an important conceptual difference between pure paths and<br>
  concrete paths;<br>
- at least six classes;<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">The docs could perhaps be more beginner friendly. For casual users, the answer is always "you want pathlib.Path".</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- about 50 or so methods and properties<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Yeah, filesystems have lots of operations. That's why before pathlib users had to learn about os and os.path and shutil and glob and maybe some more I'm forgetting.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
As far as performance goes, I don't think it matters that we could <br>
technically make pathlib imported lazily. Many people put all their <br>
pathname manipulations at the beginning of their script, so lazy or not, <br>
the pathlib module is going to be loaded *just after* startup, .<br>
<br>
For many scripts, this isn't going to matter, but for those who want to <br>
avoid the overhead of pathlib, making it lazy doesn't help. That just <br>
delays the overhead, it doesn't remove it.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">AFAIK were two situations where laziness has been mentioned in this thread:</div><div dir="auto"><br></div><div dir="auto">- my suggestion that we delay loading pathlib until someone accesses __filepath__. I don't actually know how to implement this so it was mostly intended to try to spur new ideas, but if we could do it, the point of the laziness would be so that scripts that didn't use __filepath__ wouldn't pay for it.</div><div dir="auto"><br></div><div dir="auto">- Nick's observation that pathlib could load faster if it loaded fnmatch lazily. Since this is only used for a few methods, this would benefit any script that didn't use those methods. (And for scripts that do need fnmatch's functionality, without pathlib they'd just be importing it directly, so pathlib importing it isn't really an extra cost.)</div><div dir="auto"><br></div><div dir="auto">It's true that laziness isn't a silver bullet, though, yeah. We should also look for ways to speed things up.</div><div dir="auto"><br></div><div dir="auto">-n</div></div>