Keywords
Pathlib is in the standard library since Python 3.4 and is better than os.path
for most tasks. A good overview is Trey Hunner's 2024 guide, which has a nice cheatsheet.
One really nice feature is that Path
overrides the /
operator, so instead of using the joinpath
method you can do things like this:
home = Path.home()
projects = home / "Downloads" / "projects"
It distinguishes between concrete paths (usually via Path
) which access the filesystem, and pure paths (via PurePath
) which offers path manipulations WITHOUT any actual filesystem access.
It has excellent strategies for managing paths in O/S-agonostic ways, and can resolve()
a path on a specific O/S.