[Python-ideas] __dir__ in which folder is this py file

Chris Angelico rosuav at gmail.com
Mon May 7 08:45:30 EDT 2018

On Mon, May 7, 2018 at 8:44 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, May 06, 2018 at 09:33:03PM -0700, Nathaniel Smith wrote:
>> How is
>> 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.

Isn't it strange how we can divide a path by a string, and that works,
and we can take the remainder after you divide a string by a string,
and that works as long as there's exactly one "%s" in the string, but
nobody's interested in having "foo bar spam ham"/" " ==>
["foo","bar","spam","ham"] ?

Just sayin', it ain't all that strange.


More information about the Python-ideas mailing list