Filesystem and I/O Modules
pathlib
Represents filesystem paths as objects. PurePath performs lexical operations without filesystem access; Path can inspect, create and read files. The / operator joins components. Use explicit encodings and remember that resolving a path does not prevent later filesystem changes.
Formal Syntax & Structure
python syntaxpython
import pathlibReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
from pathlib import Pathfrom tempfile import TemporaryDirectorywith TemporaryDirectory() as folder: path = Path(folder) / "note.txt" path.write_text("ready", encoding="utf-8") print(path.read_text(encoding="utf-8"), path.suffix)