Small Standard Library Projects
Path Extension Report
pathlib.PurePosixPath lets code reason about path strings without reading the host filesystem.
Path Extension Report
path_extension_report.py
from pathlib import PurePosixPath
root =
paths = [
PurePosixPath(root) / "guide" / "intro.md",
PurePosixPath(root) / "guide" / "api.md",
PurePosixPath(root) / "images" / "logo.png",
]
markdown = []
for path in paths:
if path.suffix == ".md":
markdown.append(path.stem)
print("root=" + root)
print("parent=" + paths[0].parent.as_posix())
print("markdown=" + ",".join(markdown))
from pathlib import PurePosixPath
root =
paths = [
PurePosixPath(root) / "guide" / "intro.md",
PurePosixPath(root) / "guide" / "api.md",
PurePosixPath(root) / "images" / "logo.png",
]
markdown = []
for path in paths:
if path.suffix == ".md":
markdown.append(path.stem)
print("root=" + root)
print("parent=" + paths[0].parent.as_posix())
print("markdown=" + ",".join(markdown))
from pathlib import PurePosixPath
root =
paths = [
PurePosixPath(root) / "guide" / "intro.md",
PurePosixPath(root) / "guide" / "api.md",
PurePosixPath(root) / "images" / "logo.png",
]
markdown = []
for path in paths:
if path.suffix == ".md":
markdown.append(path.stem)
print("root=" + root)
print("parent=" + paths[0].parent.as_posix())
print("markdown=" + ",".join(markdown))
pure path
A pure path parses path text only; it does not check whether files exist.