pathlib
Barry Scott
barry at barrys-emacs.org
Mon Sep 30 10:33:11 EDT 2019
> On 30 Sep 2019, at 14:20, Dan Sommers <2QdxY4RzWzUUiLuE at potatochowder.com> wrote:
>
> That's the wording I read. I inferred that "path-handling operations
> which don't actually access a filesystem" meant an object that didn't
> necessarily represent an actual file, and that "provide methods to do
> system calls on path objects" did indicate an actual file. From the
> existence of Path.read_bytes, I inferred that at least some Path objects
> represent (and operate on) actual existing files. I've been doing this
> for a long time, and I may have read my expecations into those words.
pathlib.Path() adds the semantics of operating system file rules to strings.
The addition of open(), read_bytes() etc is a convenience to the programmer.
Some people consider this a mistake other a great feature.
You can write this:
pathlib.Path("name").open()
Which is the same as:
open(pathlib.Path("name"))
Which is the same as:
open("name")
You would not expect str to track the file, why expect Path() to?
Barry
More information about the Python-list
mailing list