pathlib

Chris Angelico rosuav at gmail.com
Mon Sep 30 08:09:36 EDT 2019


On Mon, Sep 30, 2019 at 9:54 PM Dan Sommers
<2QdxY4RzWzUUiLuE at potatochowder.com> wrote:
> I would have said the same thing, but the docs⁰ disagree: a
> PurePath represents the name of (or the path to) a file, but a
> Path represents the actual file.
>>>https://docs.python.org/3/library/pathlib.html

I don't think it represents the actual file. If it did, equality would
be defined by samefile, NOT by the file name.
>>> from pathlib import Path
>>> import os
>>> open("file1", "w").close()
>>> os.link("file1", "file2")
>>> Path("file1") == Path("file2")
False
>>> Path("file1").samefile(Path("file2"))
True
>>> Path("file1") == Path("file1")
True
It still represents the path to the file, not the file itself, and if
you move something over it, it will see the new file.
ChrisA


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /