[Python-ideas] New PEP proposal -- Pathlib Module Should Contain All File Operations

Nathaniel Smith njs at pobox.com
Sun Mar 18 00:41:10 EDT 2018


On Sat, Mar 17, 2018 at 10:15 AM, Stephen J. Turnbull
<turnbull.stephen.fw at u.tsukuba.ac.jp> wrote:
> (5) perform operations on several objects denoted by Paths at once
>     (copy and its multiple operand variants),

Sure it does: Path.rename and Path.replace. I know why rename and copy
have historically been in separate modules, but the distinction is
pretty arcane and matters a lot more to implementers than it does to
users.

Similarly, it's hard to explain why we have Path.mkdir but not
Path.makedirs -- and these have historically both lived in the 'os'
module, so we can't blame it on Path being a mirror of os.path. It's
also not obvious why we should have Path.rmdir, but not Path.rmtree.

My understanding is that the point of Path is to be a convenient,
pleasant-to-use mechanism for accessing common filesystem operations.
And it does a pretty excellent job of that. But it seems obvious to me
that it's still missing a number of fairly basic operations that
people need all the time. I don't think the PEP is there yet, and we
can quibble over the details -- just copying over all the historical
decisions in shutil isn't obviously the right move (maybe it should be
Path.mkdir(include_parents=True) and Path.unlink(recursive=True)
instead of Path.makedirs and Path.rmtree?), but there's definitely
room for improvement.

-n

-- 
Nathaniel J. Smith -- https://vorpus.org


More information about the Python-ideas mailing list