pathlib

Python's standard library module for working with file paths as objects rather than plain strings.

In more detail

Path("data") / "notes.txt" joins parts with the right separator for the system, and methods such as read_text, write_text, exists, iterdir and glob do common jobs in one call. Gluing path strings with + breaks on another operating system.

Example

from pathlib import Path
for p in Path(".").iterdir():
    print(p.name)

Related terms

Taught in

References

Certification courses